From e8db174d3e464a5764a9f4bfd82172261bd50519 Mon Sep 17 00:00:00 2001 From: nsfisis Date: Sat, 21 Feb 2026 10:29:21 +0900 Subject: refactor(api): separate business logic into game, tournament, session packages MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Extract business logic from api/handler.go into dedicated service packages: - session: context helpers (resolves admin → api import dependency) - game: game state, code submission, ranking, watch logic - tournament: bracket construction and seed ordering - api/convert.go: domain → API type conversion functions api/handler.go is now a thin adapter that delegates to services and maps domain errors to HTTP status codes. Co-Authored-By: Claude Opus 4.6 --- backend/main.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'backend/main.go') diff --git a/backend/main.go b/backend/main.go index 2825b84..7220ca6 100644 --- a/backend/main.go +++ b/backend/main.go @@ -24,6 +24,7 @@ import ( "albatross-2026-backend/game" "albatross-2026-backend/ratelimit" "albatross-2026-backend/taskqueue" + "albatross-2026-backend/tournament" ) func connectDB(ctx context.Context, dsn string) (*pgxpool.Pool, error) { @@ -105,7 +106,9 @@ func main() { apiGroup.Use(ratelimit.LoginRateLimitMiddleware(loginRL)) apiGroup.Use(api.SessionCookieMiddleware(queries)) apiGroup.Use(oapimiddleware.OapiRequestValidator(openAPISpec)) - apiHandler := api.NewHandler(queries, txm, gameHub, authenticator, conf) + gameSvc := game.NewService(queries, txm, gameHub) + tournamentSvc := tournament.NewService(queries) + apiHandler := api.NewHandler(gameSvc, tournamentSvc, authenticator, queries, conf) api.RegisterHandlers(apiGroup, api.NewStrictHandler(apiHandler, nil)) adminHandler := admin.NewHandler(queries, txm, gameHub, conf) -- cgit v1.3.1