refactor: extract GameService for Connect 4 NATS/chat handling
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.
This commit is contained in:
@@ -7,19 +7,20 @@ import (
|
||||
"net/http"
|
||||
"sync"
|
||||
|
||||
"github.com/alexedwards/scs/v2"
|
||||
"github.com/go-chi/chi/v5"
|
||||
"github.com/nats-io/nats.go"
|
||||
"github.com/starfederation/datastar-go/datastar"
|
||||
|
||||
"github.com/ryanhamamura/games/config"
|
||||
"github.com/ryanhamamura/games/connect4"
|
||||
"github.com/ryanhamamura/games/db/repository"
|
||||
"github.com/ryanhamamura/games/features/auth"
|
||||
"github.com/ryanhamamura/games/features/c4game"
|
||||
"github.com/ryanhamamura/games/features/c4game/services"
|
||||
"github.com/ryanhamamura/games/features/lobby"
|
||||
"github.com/ryanhamamura/games/features/snakegame"
|
||||
"github.com/ryanhamamura/games/snake"
|
||||
|
||||
"github.com/alexedwards/scs/v2"
|
||||
"github.com/go-chi/chi/v5"
|
||||
"github.com/nats-io/nats.go"
|
||||
"github.com/starfederation/datastar-go/datastar"
|
||||
)
|
||||
|
||||
func SetupRoutes(
|
||||
@@ -40,9 +41,12 @@ func SetupRoutes(
|
||||
setupReload(router)
|
||||
}
|
||||
|
||||
// Services
|
||||
c4Svc := services.NewGameService(nc, queries)
|
||||
|
||||
auth.SetupRoutes(router, queries, sessions)
|
||||
lobby.SetupRoutes(router, queries, sessions, store, snakeStore)
|
||||
c4game.SetupRoutes(router, store, nc, sessions, queries)
|
||||
c4game.SetupRoutes(router, store, c4Svc, sessions)
|
||||
snakegame.SetupRoutes(router, snakeStore, nc, sessions)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user