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