refactor: streamline routes to RESTful naming conventions
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=)
This commit is contained in:
@@ -22,7 +22,7 @@ import (
|
||||
|
||||
func HandleGamePage(store *game.GameStore, sessions *scs.SessionManager, queries *repository.Queries) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
gameID := chi.URLParam(r, "game_id")
|
||||
gameID := chi.URLParam(r, "id")
|
||||
|
||||
gi, exists := store.Get(gameID)
|
||||
if !exists {
|
||||
@@ -87,7 +87,7 @@ func HandleGamePage(store *game.GameStore, sessions *scs.SessionManager, queries
|
||||
|
||||
func HandleGameEvents(store *game.GameStore, nc *nats.Conn, sessions *scs.SessionManager, queries *repository.Queries) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
gameID := chi.URLParam(r, "game_id")
|
||||
gameID := chi.URLParam(r, "id")
|
||||
|
||||
gi, exists := store.Get(gameID)
|
||||
if !exists {
|
||||
@@ -173,7 +173,7 @@ func HandleGameEvents(store *game.GameStore, nc *nats.Conn, sessions *scs.Sessio
|
||||
|
||||
func HandleDropPiece(store *game.GameStore, sessions *scs.SessionManager) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
gameID := chi.URLParam(r, "game_id")
|
||||
gameID := chi.URLParam(r, "id")
|
||||
|
||||
gi, exists := store.Get(gameID)
|
||||
if !exists {
|
||||
@@ -210,7 +210,7 @@ func HandleDropPiece(store *game.GameStore, sessions *scs.SessionManager) http.H
|
||||
|
||||
func HandleSendChat(store *game.GameStore, nc *nats.Conn, sessions *scs.SessionManager, queries *repository.Queries) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
gameID := chi.URLParam(r, "game_id")
|
||||
gameID := chi.URLParam(r, "id")
|
||||
|
||||
gi, exists := store.Get(gameID)
|
||||
if !exists {
|
||||
@@ -276,7 +276,7 @@ func HandleSendChat(store *game.GameStore, nc *nats.Conn, sessions *scs.SessionM
|
||||
|
||||
func HandleSetNickname(store *game.GameStore, sessions *scs.SessionManager) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
gameID := chi.URLParam(r, "game_id")
|
||||
gameID := chi.URLParam(r, "id")
|
||||
|
||||
gi, exists := store.Get(gameID)
|
||||
if !exists {
|
||||
@@ -319,13 +319,13 @@ func HandleSetNickname(store *game.GameStore, sessions *scs.SessionManager) http
|
||||
}
|
||||
|
||||
sse := datastar.NewSSE(w, r)
|
||||
sse.Redirect("/game/" + gameID) //nolint:errcheck
|
||||
sse.Redirect("/games/" + gameID) //nolint:errcheck
|
||||
}
|
||||
}
|
||||
|
||||
func HandleRematch(store *game.GameStore, sessions *scs.SessionManager) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
gameID := chi.URLParam(r, "game_id")
|
||||
gameID := chi.URLParam(r, "id")
|
||||
|
||||
gi, exists := store.Get(gameID)
|
||||
if !exists {
|
||||
@@ -337,7 +337,7 @@ func HandleRematch(store *game.GameStore, sessions *scs.SessionManager) http.Han
|
||||
newGI := gi.CreateRematch(store)
|
||||
sse := datastar.NewSSE(w, r)
|
||||
if newGI != nil {
|
||||
sse.Redirectf("/game/%s", newGI.ID()) //nolint:errcheck
|
||||
sse.Redirectf("/games/%s", newGI.ID()) //nolint:errcheck
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user