Browse Source

add routes for new pages

pull/1/head
Stephanie Gredell 7 months ago
parent
commit
ae1e546c26
  1. 0
      router/handlers/game.go
  2. 22
      router/handlers/mode.go
  3. 49
      router/handlers/simulation.go
  4. 3
      router/router.go

0
router/handlers/simulate.go → router/handlers/game.go

22
router/handlers/mode.go

@ -0,0 +1,22 @@ @@ -0,0 +1,22 @@
package handlers
import (
"html/template"
"net/http"
)
type ModeHandler struct {
Tmpl *template.Template
}
func (m *ModeHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) {
data := struct {
Title string
}{
Title: "Title",
}
if err := m.Tmpl.ExecuteTemplate(w, "game-mode.html", data); err != nil {
http.Error(w, "Template Error", http.StatusInternalServerError)
}
}

49
router/handlers/simulation.go

@ -0,0 +1,49 @@ @@ -0,0 +1,49 @@
package handlers
import (
"encoding/json"
"net/http"
"systemdesigngame/internal/design"
)
type SimulationHandler struct{}
type SimulationResponse struct {
Success bool `json:"success"`
Metrics map[string]interface{} `json:"metrics,omitempty"`
Timeline []interface{} `json:"timeline,omitempty"`
Error string `json:"error,omitempty"`
}
func (h *SimulationHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
if r.Method != http.MethodPost {
http.Error(w, "Method not allowed", http.StatusMethodNotAllowed)
return
}
var design design.Design
if err := json.NewDecoder(r.Body).Decode(&design); err != nil {
http.Error(w, "Invalid design JSON: "+err.Error(), http.StatusBadRequest)
return
}
// TODO: Run simulation engine here
// For now, return a mock successful response but eventually, we want to go to the results page(s)
response := SimulationResponse{
Success: true,
Metrics: map[string]interface{}{
"throughput": 250,
"latency_p95": 85,
"cost_monthly": 120,
"availability": 99.5,
},
Timeline: []interface{}{}, // Will contain TickSnapshots later
}
w.Header().Set("Content-Type", "application/json")
if err := json.NewEncoder(w).Encode(response); err != nil {
http.Error(w, "Failed to encode response", http.StatusInternalServerError)
return
}
}

3
router/router.go

@ -12,7 +12,10 @@ func SetupRoutes(tmpl *template.Template) *http.ServeMux { @@ -12,7 +12,10 @@ func SetupRoutes(tmpl *template.Template) *http.ServeMux {
mux := http.NewServeMux()
mux.Handle("/static/", http.StripPrefix("/static/", http.FileServer(http.Dir("static"))))
mux.Handle("/", &handlers.HomeHandler{Tmpl: tmpl})
mux.Handle("/mode", auth.RequireAuth(&handlers.PlayHandler{Tmpl: tmpl}))
mux.Handle("/play/", auth.RequireAuth(&handlers.PlayHandler{Tmpl: tmpl}))
mux.Handle("/simulate", auth.RequireAuth(&handlers.SimulationHandler{}))
mux.HandleFunc("/login", auth.LoginHandler)
mux.HandleFunc("/callback", auth.CallbackHandler)

Loading…
Cancel
Save