diff options
Diffstat (limited to 'backend')
| -rw-r--r-- | backend/api/handler.go | 4 | ||||
| -rw-r--r-- | backend/game/service.go | 8 |
2 files changed, 6 insertions, 6 deletions
diff --git a/backend/api/handler.go b/backend/api/handler.go index 4d729f1..ad7d55a 100644 --- a/backend/api/handler.go +++ b/backend/api/handler.go @@ -236,7 +236,7 @@ func (h *Handler) GetGamePlaySubmissions(ctx context.Context, request GetGamePla } func (h *Handler) PostGamePlayCode(ctx context.Context, request PostGamePlayCodeRequestObject, user *db.User) (PostGamePlayCodeResponseObject, error) { - err := h.gameSvc.SaveCode(ctx, request.GameID, user.UserID, request.Body.Code) + err := h.gameSvc.SaveCode(ctx, request.GameID, user.UserID, request.Body.Code, user.IsAdmin) if err != nil { if errors.Is(err, game.ErrNotFound) { return PostGamePlayCode404JSONResponse{Message: "Game not found"}, nil @@ -250,7 +250,7 @@ func (h *Handler) PostGamePlayCode(ctx context.Context, request PostGamePlayCode } func (h *Handler) PostGamePlaySubmit(ctx context.Context, request PostGamePlaySubmitRequestObject, user *db.User) (PostGamePlaySubmitResponseObject, error) { - err := h.gameSvc.SubmitCode(ctx, request.GameID, user.UserID, request.Body.Code) + err := h.gameSvc.SubmitCode(ctx, request.GameID, user.UserID, request.Body.Code, user.IsAdmin) if err != nil { if errors.Is(err, game.ErrNotFound) { return PostGamePlaySubmit404JSONResponse{}, nil 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 } |
