From 2794e9de67781614edc17336b284266d3e4a740c Mon Sep 17 00:00:00 2001 From: nsfisis Date: Sat, 28 Feb 2026 15:04:21 +0900 Subject: feat(admin): allow admin users to view and submit code before game starts Admin users can now access the gaming UI (problem description, code editor, submit button) even when a game has not started yet. Regular users still see the waiting screen as before. Co-Authored-By: Claude Opus 4.6 --- backend/game/service.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'backend/game') diff --git a/backend/game/service.go b/backend/game/service.go index 13900e1..a054388 100644 --- a/backend/game/service.go +++ b/backend/game/service.go @@ -202,7 +202,7 @@ func (s *Service) GetGameByID(ctx context.Context, gameID int, isAdmin bool) (De return game, nil } -func (s *Service) SaveCode(ctx context.Context, gameID int, userID int32, code string) error { +func (s *Service) SaveCode(ctx context.Context, gameID int, userID int32, code string, isAdmin bool) error { gameRow, err := s.q.GetGameByID(ctx, int32(gameID)) if err != nil { if errors.Is(err, pgx.ErrNoRows) { @@ -210,7 +210,7 @@ func (s *Service) SaveCode(ctx context.Context, gameID int, userID int32, code s } return err } - if !IsGameRunning(gameRow.StartedAt, gameRow.DurationSeconds) { + if !IsGameRunning(gameRow.StartedAt, gameRow.DurationSeconds) && !isAdmin { return ErrGameNotRunning } return s.q.UpdateCode(ctx, db.UpdateCodeParams{ @@ -221,7 +221,7 @@ func (s *Service) SaveCode(ctx context.Context, gameID int, userID int32, code s }) } -func (s *Service) SubmitCode(ctx context.Context, gameID int, userID int32, code string) error { +func (s *Service) SubmitCode(ctx context.Context, gameID int, userID int32, code string, isAdmin bool) error { gameRow, err := s.q.GetGameByID(ctx, int32(gameID)) if err != nil { if errors.Is(err, pgx.ErrNoRows) { @@ -233,7 +233,7 @@ func (s *Service) SubmitCode(ctx context.Context, gameID int, userID int32, code language := gameRow.Language codeSize := s.hub.CalcCodeSize(code, language) - if !IsGameRunning(gameRow.StartedAt, gameRow.DurationSeconds) { + if !IsGameRunning(gameRow.StartedAt, gameRow.DurationSeconds) && !isAdmin { return ErrGameNotRunning } -- cgit v1.3.1