This commit is contained in:
2026-10-01 16:42:39 +07:00
parent 5638349623
commit ee15d149bd
31 changed files with 37 additions and 88 deletions
-1
View File
@@ -25,7 +25,6 @@ type Repo struct {
pool *pgxpool.Pool
}
// NewGameMapRepo создаёт repository объектов карты.
func NewGameMapRepo(pool *pgxpool.Pool) *Repo {
return &Repo{pool: pool}
}
+3 -2
View File
@@ -76,7 +76,7 @@ func (r *TeamsRepo) AnswerParticipation(ctx context.Context, token, answer strin
if err != nil {
return nil, err
}
// The condition is rechecked after a concurrent answer releases its row lock.
// Условие проверяется повторно после снятия блокировки строки конкурентным ответом.
_, err = r.pool.Exec(ctx, `WITH eligible_game AS (SELECT g.id FROM games g JOIN teams t ON t.game_id=g.id
WHERE t.participation_token_hash=$1 AND g.status='draft' AND g.start_at > (clock_timestamp() AT TIME ZONE 'UTC') FOR SHARE OF g)
UPDATE teams t SET participation_status=$2,
@@ -99,7 +99,8 @@ func (r *TeamsRepo) AnswerParticipation(ctx context.Context, token, answer strin
return p, ErrParticipationClosed
}
// A five-minute lease survives restarts and keeps concurrent workers from sending the same job.
// Пятиминутная аренда переживает перезапуски и не позволяет рабочим процессам
// отправить одну задачу повторно.
func (r *TeamsRepo) ClaimParticipationEmail(ctx context.Context) (*Participation, error) {
p := &Participation{}
err := r.pool.QueryRow(ctx, `WITH candidate AS (
+1 -1
View File
@@ -212,7 +212,7 @@ func (r *TeamsRepo) RegisterTeamWithParticipation(ctx context.Context, gameID in
return id, err
}
// GetActiveTeamsByGameID excludes cancelled registrations from gameplay exports and results.
// GetActiveTeamsByGameID исключает отменённые регистрации из игровых выгрузок и результатов.
func (r *TeamsRepo) GetActiveTeamsByGameID(ctx context.Context, gameID int) ([]*repos.Team, error) {
teams, err := r.GetTeamsByGameID(ctx, gameID)
active := teams[:0]
+1 -1
View File
@@ -77,7 +77,7 @@ func (s *UsersRepo) AddUserWithAgreements(
// создать пользователя с тем же username/email — нарушение
// уникальности. Возвращаем тот же понятный клиенту ответ.
var pgErr *pgconn.PgError
if errors.As(err, &pgErr) && pgErr.Code == "23505" { // unique_violation
if errors.As(err, &pgErr) && pgErr.Code == "23505" { // нарушение уникальности
return 0, errors.New("Username или email уже используется")
}
return 0, err