lint competition service

This commit is contained in:
Timur Kh.
2025-12-17 12:41:03 +03:00
parent 4c7e35dafd
commit 39b5f05d39
7 changed files with 64 additions and 20 deletions
@@ -25,7 +25,11 @@ type CompetitionRepository struct {
cacheEnabled bool
}
func NewCompetitionRepository(db *sqlx.DB, redisClient *redis.Client, cacheEnabled bool) repository.CompetitionRepository {
func NewCompetitionRepository(
db *sqlx.DB,
redisClient *redis.Client,
cacheEnabled bool,
) repository.CompetitionRepository {
return &CompetitionRepository{
db: db,
redisClient: redisClient,
@@ -140,7 +144,10 @@ func (r *CompetitionRepository) Delete(ctx context.Context, id uuid.UUID) error
return nil
}
func (r *CompetitionRepository) List(ctx context.Context, opts repository.ListCompetitionsOptions) ([]*pb.Competition, int, error) {
func (r *CompetitionRepository) List(
ctx context.Context,
opts repository.ListCompetitionsOptions,
) ([]*pb.Competition, int, error) {
var args []interface{}
var whereClauses []string
argId := 1
@@ -163,7 +170,10 @@ func (r *CompetitionRepository) List(ctx context.Context, opts repository.ListCo
}
if *opts.IsParticipating {
whereClauses = append(whereClauses, fmt.Sprintf("id IN (SELECT competition_id FROM user_competitions WHERE user_id = $%d)", argId))
whereClauses = append(
whereClauses,
fmt.Sprintf("id IN (SELECT competition_id FROM user_competitions WHERE user_id = $%d)", argId),
)
} else {
whereClauses = append(whereClauses, fmt.Sprintf("id NOT IN (SELECT competition_id FROM user_competitions WHERE user_id = $%d)", argId))
}
@@ -182,7 +192,12 @@ func (r *CompetitionRepository) List(ctx context.Context, opts repository.ListCo
return nil, 0, err
}
query := fmt.Sprintf(`SELECT id, state, title, description, image_url, start_time, end_time, type, participation_type, created_at, updated_at FROM competitions %s ORDER BY created_at DESC LIMIT $%d OFFSET $%d`, where, argId, argId+1)
query := fmt.Sprintf(
`SELECT id, state, title, description, image_url, start_time, end_time, type, participation_type, created_at, updated_at FROM competitions %s ORDER BY created_at DESC LIMIT $%d OFFSET $%d`,
where,
argId,
argId+1,
)
args = append(args, opts.PageSize, (opts.Page-1)*opts.PageSize)
var competitions []*pb.Competition
@@ -194,7 +209,11 @@ func (r *CompetitionRepository) List(ctx context.Context, opts repository.ListCo
return competitions, total, nil
}
func (r *CompetitionRepository) ChangeState(ctx context.Context, id uuid.UUID, state pb.CompetitionState) (*pb.Competition, error) {
func (r *CompetitionRepository) ChangeState(
ctx context.Context,
id uuid.UUID,
state pb.CompetitionState,
) (*pb.Competition, error) {
query := `UPDATE competitions SET state = $1, updated_at = $2 WHERE id = $3 RETURNING updated_at`
now := time.Now()
var competition pb.Competition
@@ -208,4 +227,4 @@ func (r *CompetitionRepository) ChangeState(ctx context.Context, id uuid.UUID, s
}
return r.Get(ctx, id)
}
}