generated from VLADIMIR/template
update gave application
This commit is contained in:
@@ -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
|
||||||
|
}
|
||||||
|
|||||||
@@ -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) {
|
||||||
|
|||||||
Reference in New Issue
Block a user