refactor: streamline routes to RESTful naming conventions
All checks were successful
CI / Deploy / test (pull_request) Successful in 13s
CI / Deploy / lint (pull_request) Successful in 23s
CI / Deploy / deploy (pull_request) Has been skipped

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:
Ryan Hamamura
2026-03-02 13:19:03 -10:00
parent fcc6b70e84
commit 5120eef776
18 changed files with 82 additions and 86 deletions

View File

@@ -81,9 +81,9 @@ func column(g *game.Game, colIdx int, myColor int) templ.Component {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var3 string
templ_7745c5c3_Var3, templ_7745c5c3_Err = templ.JoinStringErrs(datastar.PostSSE("/api/game/%s/drop?col=%d", g.ID, colIdx))
templ_7745c5c3_Var3, templ_7745c5c3_Err = templ.JoinStringErrs(datastar.PostSSE("/games/%s/drop?col=%d", g.ID, colIdx))
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `features/c4game/components/board.templ`, Line: 22, Col: 77}
return templ.Error{Err: templ_7745c5c3_Err, FileName: `features/c4game/components/board.templ`, Line: 22, Col: 74}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var3))
if templ_7745c5c3_Err != nil {

View File

@@ -105,9 +105,9 @@ func Chat(messages []ChatMessage, gameID string) templ.Component {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var5 string
templ_7745c5c3_Var5, templ_7745c5c3_Err = templ.JoinStringErrs(datastar.PostSSE("/api/game/%s/chat", gameID))
templ_7745c5c3_Var5, templ_7745c5c3_Err = templ.JoinStringErrs(datastar.PostSSE("/games/%s/chat", gameID))
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `features/c4game/components/chat.templ`, Line: 40, Col: 73}
return templ.Error{Err: templ_7745c5c3_Err, FileName: `features/c4game/components/chat.templ`, Line: 40, Col: 70}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var5))
if templ_7745c5c3_Err != nil {
@@ -118,9 +118,9 @@ func Chat(messages []ChatMessage, gameID string) templ.Component {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var6 string
templ_7745c5c3_Var6, templ_7745c5c3_Err = templ.JoinStringErrs(datastar.PostSSE("/api/game/%s/chat", gameID))
templ_7745c5c3_Var6, templ_7745c5c3_Err = templ.JoinStringErrs(datastar.PostSSE("/games/%s/chat", gameID))
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `features/c4game/components/chat.templ`, Line: 44, Col: 65}
return templ.Error{Err: templ_7745c5c3_Err, FileName: `features/c4game/components/chat.templ`, Line: 44, Col: 62}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var6))
if templ_7745c5c3_Err != nil {

View File

@@ -77,9 +77,9 @@ func StatusBanner(g *game.Game, myColor int) templ.Component {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var5 templ.SafeURL
templ_7745c5c3_Var5, templ_7745c5c3_Err = templ.JoinURLErrs(templ.SafeURL("/game/" + *g.RematchGameID))
templ_7745c5c3_Var5, templ_7745c5c3_Err = templ.JoinURLErrs(templ.SafeURL("/games/" + *g.RematchGameID))
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `features/c4game/components/status.templ`, Line: 16, Col: 54}
return templ.Error{Err: templ_7745c5c3_Err, FileName: `features/c4game/components/status.templ`, Line: 16, Col: 55}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var5))
if templ_7745c5c3_Err != nil {
@@ -95,9 +95,9 @@ func StatusBanner(g *game.Game, myColor int) templ.Component {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var6 string
templ_7745c5c3_Var6, templ_7745c5c3_Err = templ.JoinStringErrs(datastar.PostSSE("/api/game/%s/rematch", g.ID))
templ_7745c5c3_Var6, templ_7745c5c3_Err = templ.JoinStringErrs(datastar.PostSSE("/games/%s/rematch", g.ID))
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `features/c4game/components/status.templ`, Line: 24, Col: 67}
return templ.Error{Err: templ_7745c5c3_Err, FileName: `features/c4game/components/status.templ`, Line: 24, Col: 64}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var6))
if templ_7745c5c3_Err != nil {
@@ -217,9 +217,9 @@ func InviteLink(gameID string) templ.Component {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var12 string
templ_7745c5c3_Var12, templ_7745c5c3_Err = templ.JoinStringErrs(config.Global.AppURL + "/game/" + gameID)
templ_7745c5c3_Var12, templ_7745c5c3_Err = templ.JoinStringErrs(config.Global.AppURL + "/games/" + gameID)
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `features/c4game/components/status.templ`, Line: 48, Col: 45}
return templ.Error{Err: templ_7745c5c3_Err, FileName: `features/c4game/components/status.templ`, Line: 48, Col: 46}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var12))
if templ_7745c5c3_Err != nil {
@@ -229,7 +229,7 @@ func InviteLink(gameID string) templ.Component {
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = templ.RenderScriptItems(ctx, templ_7745c5c3_Buffer, copyToClipboard(config.Global.AppURL+"/game/"+gameID))
templ_7745c5c3_Err = templ.RenderScriptItems(ctx, templ_7745c5c3_Buffer, copyToClipboard(config.Global.AppURL+"/games/"+gameID))
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
@@ -237,7 +237,7 @@ func InviteLink(gameID string) templ.Component {
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var13 templ.ComponentScript = copyToClipboard(config.Global.AppURL + "/game/" + gameID)
var templ_7745c5c3_Var13 templ.ComponentScript = copyToClipboard(config.Global.AppURL + "/games/" + gameID)
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var13.Call)
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err

View File

@@ -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
}
}
}

View File

@@ -54,9 +54,9 @@ func GamePage(g *game.Game, myColor int, messages []components.ChatMessage) temp
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var3 string
templ_7745c5c3_Var3, templ_7745c5c3_Err = templ.JoinStringErrs(datastar.GetSSE("/game/%s/events", g.ID))
templ_7745c5c3_Var3, templ_7745c5c3_Err = templ.JoinStringErrs(datastar.GetSSE("/games/%s/events", g.ID))
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `features/c4game/pages/game.templ`, Line: 16, Col: 55}
return templ.Error{Err: templ_7745c5c3_Err, FileName: `features/c4game/pages/game.templ`, Line: 16, Col: 56}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var3))
if templ_7745c5c3_Err != nil {
@@ -152,9 +152,9 @@ func JoinPage(gameID string) templ.Component {
}
ctx = templ.InitializeContext(ctx)
templ_7745c5c3_Err = sharedcomponents.GameJoinPrompt(
"/login?return_url=/game/"+gameID,
"/register?return_url=/game/"+gameID,
"/game/"+gameID,
"/login?return_url=/games/"+gameID,
"/register?return_url=/games/"+gameID,
"/games/"+gameID,
).Render(ctx, templ_7745c5c3_Buffer)
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
@@ -202,7 +202,7 @@ func NicknamePage(gameID string) templ.Component {
}()
}
ctx = templ.InitializeContext(ctx)
templ_7745c5c3_Err = sharedcomponents.NicknamePrompt("/api/game/"+gameID+"/join").Render(ctx, templ_7745c5c3_Buffer)
templ_7745c5c3_Err = sharedcomponents.NicknamePrompt("/games/"+gameID+"/join").Render(ctx, templ_7745c5c3_Buffer)
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}

View File

@@ -17,10 +17,9 @@ func SetupRoutes(
sessions *scs.SessionManager,
queries *repository.Queries,
) error {
router.Get("/game/{game_id}", HandleGamePage(store, sessions, queries))
router.Get("/game/{game_id}/events", HandleGameEvents(store, nc, sessions, queries))
router.Route("/api/game/{game_id}", func(r chi.Router) {
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))