Remove /api/ prefix and consolidate route groups:
- /api/lobby/* -> /games, /snake, /logout (top-level)
- /game/{game_id} + /api/game/{game_id}/* -> /games/{id}/*
- /snake/{game_id} + /api/snake/{game_id}/* -> /snake/{id}/*
- /api/auth/* -> /auth/*
- Standardize snake join page to use return_url= (was return=)
31 lines
842 B
Go
31 lines
842 B
Go
// Package c4game handles Connect 4 game routes, SSE event streaming, and chat.
|
|
package c4game
|
|
|
|
import (
|
|
"github.com/alexedwards/scs/v2"
|
|
"github.com/go-chi/chi/v5"
|
|
"github.com/nats-io/nats.go"
|
|
|
|
"github.com/ryanhamamura/c4/db/repository"
|
|
"github.com/ryanhamamura/c4/game"
|
|
)
|
|
|
|
func SetupRoutes(
|
|
router chi.Router,
|
|
store *game.GameStore,
|
|
nc *nats.Conn,
|
|
sessions *scs.SessionManager,
|
|
queries *repository.Queries,
|
|
) error {
|
|
router.Route("/games/{id}", func(r chi.Router) {
|
|
r.Get("/", HandleGamePage(store, sessions, queries))
|
|
r.Get("/events", HandleGameEvents(store, nc, sessions, queries))
|
|
r.Post("/drop", HandleDropPiece(store, sessions))
|
|
r.Post("/chat", HandleSendChat(store, nc, sessions, queries))
|
|
r.Post("/join", HandleSetNickname(store, sessions))
|
|
r.Post("/rematch", HandleRematch(store, sessions))
|
|
})
|
|
|
|
return nil
|
|
}
|