This commit is contained in:
2026-10-03 13:00:50 +07:00
parent dd55079e06
commit 7a7808b4d1
28 changed files with 191 additions and 11 deletions
+8
View File
@@ -9,24 +9,29 @@ import (
)
var (
// ErrActionsNotFound indicates that no actions were found.
ErrActionsNotFound = errors.New("Ход не найден")
)
// ActionsRepo persists team actions.
type ActionsRepo struct {
pool *pgxpool.Pool
}
// Action describes a team action.
type Action struct {
Code string
ViaMCP bool
}
// NewActionsRepo creates an actions repository.
func NewActionsRepo(pool *pgxpool.Pool) *ActionsRepo {
return &ActionsRepo{
pool: pool,
}
}
// AddAction stores an action for a team.
func (r *ActionsRepo) AddAction(ctx context.Context, teamID int, code string, viaMCP bool) (int, error) {
id := 0
err := r.pool.QueryRow(
@@ -45,6 +50,7 @@ func (r *ActionsRepo) AddAction(ctx context.Context, teamID int, code string, vi
return id, nil
}
// GetActionsByTeamID returns actions for a team.
func (r *ActionsRepo) GetActionsByTeamID(ctx context.Context, teamID int) ([]Action, error) {
rows, err := r.pool.Query(
ctx,
@@ -80,6 +86,7 @@ func (r *ActionsRepo) GetActionsByTeamID(ctx context.Context, teamID int) ([]Act
return actions, nil
}
// GetActionsCountByTeamIDs returns action counts for teams.
func (r *ActionsRepo) GetActionsCountByTeamIDs(ctx context.Context, teamIDs []int) (map[int]int, error) {
rows, err := r.pool.Query(
ctx,
@@ -116,6 +123,7 @@ func (r *ActionsRepo) GetActionsCountByTeamIDs(ctx context.Context, teamIDs []in
return res, nil
}
// DeleteLastActionByTeamID removes the latest action for a team.
func (r *ActionsRepo) DeleteLastActionByTeamID(ctx context.Context, teamID int) error {
tag, err := r.pool.Exec(
ctx,