update gave application

This commit is contained in:
2026-07-28 21:30:28 +07:00
parent 20662dc9da
commit 5e3584e31a
2 changed files with 33 additions and 2 deletions
+32 -1
View File
@@ -2,11 +2,16 @@ package applications_repo
import ( import (
"context" "context"
"errors"
"evening_detective_server/internal/repos" "evening_detective_server/internal/repos"
"github.com/jackc/pgx/v5/pgxpool" "github.com/jackc/pgx/v5/pgxpool"
) )
var (
ErrApplicationNotFound = errors.New("Улика не найдена")
)
type ApplicationsRepo struct { type ApplicationsRepo struct {
pool *pgxpool.Pool pool *pgxpool.Pool
} }
@@ -52,8 +57,9 @@ func (r *ApplicationsRepo) GetApplicationsByTeamIDsAndState(
image, image,
team_id team_id
FROM applications FROM applications
WHERE team_id = ANY($1)`, WHERE team_id = ANY($1) and status = $2`,
teamIds, teamIds,
state,
) )
if err != nil { if err != nil {
return nil, err return nil, err
@@ -79,3 +85,28 @@ func (r *ApplicationsRepo) GetApplicationsByTeamIDsAndState(
return res, nil 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
}
+1 -1
View File
@@ -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 { 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) { func (s *GameService) GetTeamActions(ctx context.Context, teamId int, password string) (*storytelling.Story, error) {