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/gen/api/handler_wrapper_gen.go | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) (limited to 'backend/gen/api/handler_wrapper_gen.go') diff --git a/backend/gen/api/handler_wrapper_gen.go b/backend/gen/api/handler_wrapper_gen.go index 88f55c6..ef2baa1 100644 --- a/backend/gen/api/handler_wrapper_gen.go +++ b/backend/gen/api/handler_wrapper_gen.go @@ -117,6 +117,9 @@ import ( "albatross-2026-backend/config" "albatross-2026-backend/db" + "albatross-2026-backend/game" + "albatross-2026-backend/session" + "albatross-2026-backend/tournament" ) var _ StrictServerInterface = (*HandlerWrapper)(nil) @@ -125,14 +128,14 @@ type HandlerWrapper struct { impl Handler } -func NewHandler(queries db.Querier, txm db.TxManager, hub GameHubInterface, auth AuthenticatorInterface, conf *config.Config) *HandlerWrapper { +func NewHandler(gameSvc *game.Service, tournamentSvc *tournament.Service, auth AuthenticatorInterface, queries db.Querier, conf *config.Config) *HandlerWrapper { return &HandlerWrapper{ impl: Handler{ - q: queries, - txm: txm, - hub: hub, - auth: auth, - conf: conf, + gameSvc: gameSvc, + tournamentSvc: tournamentSvc, + auth: auth, + conf: conf, + q: queries, }, } } @@ -140,7 +143,7 @@ func NewHandler(queries db.Querier, txm db.TxManager, hub GameHubInterface, auth {{ range . }} func (h *HandlerWrapper) {{ .Name }}(ctx context.Context, request {{ .Name }}RequestObject) ({{ .Name }}ResponseObject, error) { {{ if .RequiresLogin -}} - user, ok := GetUserFromContext(ctx) + user, ok := session.GetUserFromContext(ctx) if !ok { return {{ .Name }}401JSONResponse{ Message: "Unauthorized", @@ -155,7 +158,7 @@ func NewHandler(queries db.Querier, txm db.TxManager, hub GameHubInterface, auth {{ end -}} return h.impl.{{ .Name }}(ctx, request, user) {{ else if .LoginOptional -}} - user, _ := GetUserFromContext(ctx) + user, _ := session.GetUserFromContext(ctx) return h.impl.{{ .Name }}(ctx, request, user) {{ else -}} return h.impl.{{ .Name }}(ctx, request) -- cgit v1.3.1