add last action delete

This commit is contained in:
2026-07-28 22:00:00 +07:00
parent 5e3584e31a
commit 7aa8a50e30
6 changed files with 80 additions and 15 deletions
+27
View File
@@ -2,10 +2,15 @@ package actions_repo
import (
"context"
"errors"
"github.com/jackc/pgx/v5/pgxpool"
)
var (
ErrActionsNotFound = errors.New("Ход не найден")
)
type ActionsRepo struct {
pool *pgxpool.Pool
}
@@ -101,3 +106,25 @@ func (r *ActionsRepo) GetActionsCountByTeamIDs(ctx context.Context, teamIds []in
return res, nil
}
func (r *ActionsRepo) DeleteLastActionByTeamId(ctx context.Context, teamId int) error {
tag, err := r.pool.Exec(
ctx,
`DELETE FROM actions
WHERE id IN (
SELECT id
FROM actions
WHERE team_id = $1
ORDER BY created_at DESC
LIMIT 1
)`,
teamId,
)
if err != nil {
return err
}
if tag.RowsAffected() == 0 {
return ErrActionsNotFound
}
return nil
}