Move NATS subscription and chat room management into a dedicated GameService, following the portigo service pattern. Handlers now receive the service and call its methods instead of managing NATS connections directly.
27 lines
776 B
Go
27 lines
776 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/ryanhamamura/games/connect4"
|
|
"github.com/ryanhamamura/games/features/c4game/services"
|
|
)
|
|
|
|
func SetupRoutes(
|
|
router chi.Router,
|
|
store *connect4.Store,
|
|
svc *services.GameService,
|
|
sessions *scs.SessionManager,
|
|
) {
|
|
router.Route("/games/{id}", func(r chi.Router) {
|
|
r.Get("/", HandleGamePage(store, svc, sessions))
|
|
r.Get("/events", HandleGameEvents(store, svc, sessions))
|
|
r.Post("/drop", HandleDropPiece(store, sessions))
|
|
r.Post("/chat", HandleSendChat(store, svc, sessions))
|
|
r.Post("/join", HandleSetNickname(store, sessions))
|
|
r.Post("/rematch", HandleRematch(store, sessions))
|
|
})
|
|
}
|