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 (
"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
}