From 5e3584e31af2c077cbba1feb4e3ae150860e62a8 Mon Sep 17 00:00:00 2001 From: Fedorov Vladimir Date: Tue, 28 Jul 2026 21:30:28 +0700 Subject: [PATCH] update gave application --- internal/repos/applications_repo/repo.go | 33 ++++++++++++++++++++++- internal/services/game_service/service.go | 2 +- 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/internal/repos/applications_repo/repo.go b/internal/repos/applications_repo/repo.go index b08a6e5..137d80e 100644 --- a/internal/repos/applications_repo/repo.go +++ b/internal/repos/applications_repo/repo.go @@ -2,11 +2,16 @@ package applications_repo import ( "context" + "errors" "evening_detective_server/internal/repos" "github.com/jackc/pgx/v5/pgxpool" ) +var ( + ErrApplicationNotFound = errors.New("Улика не найдена") +) + type ApplicationsRepo struct { pool *pgxpool.Pool } @@ -52,8 +57,9 @@ func (r *ApplicationsRepo) GetApplicationsByTeamIDsAndState( image, team_id FROM applications - WHERE team_id = ANY($1)`, + WHERE team_id = ANY($1) and status = $2`, teamIds, + state, ) if err != nil { return nil, err @@ -79,3 +85,28 @@ func (r *ApplicationsRepo) GetApplicationsByTeamIDsAndState( return res, nil } + +func (r *ApplicationsRepo) UpdateApplicationStatus( + ctx context.Context, + teamId int, + name string, + status string, +) error { + tag, err := r.pool.Exec( + ctx, + `UPDATE applications + SET + status = $1 + WHERE team_id = $2 and name = $3`, + status, + teamId, + name, + ) + if err != nil { + return err + } + if tag.RowsAffected() == 0 { + return ErrApplicationNotFound + } + return nil +} diff --git a/internal/services/game_service/service.go b/internal/services/game_service/service.go index b97b847..dfa5e33 100644 --- a/internal/services/game_service/service.go +++ b/internal/services/game_service/service.go @@ -166,7 +166,7 @@ func (s *GameService) DeleteTeam(ctx context.Context, teamId int) error { } func (s *GameService) GiveTeamApplications(ctx context.Context, teamId int, name string) error { - panic("unimplemented") + return s.applicationsRepo.UpdateApplicationStatus(ctx, teamId, name, "done") } func (s *GameService) GetTeamActions(ctx context.Context, teamId int, password string) (*storytelling.Story, error) {