style: reformatted all files
This commit is contained in:
@@ -3,13 +3,14 @@ package postgres
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"datarush/internal/results/domain"
|
||||
"datarush/internal/results/repository"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"datarush/internal/results/domain"
|
||||
"datarush/internal/results/repository"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"github.com/lib/pq"
|
||||
"github.com/redis/go-redis/v9"
|
||||
@@ -257,8 +258,13 @@ func (r *ResultRepository) List(ctx context.Context, opts repository.ListResults
|
||||
return nil, 0, err
|
||||
}
|
||||
|
||||
query := fmt.Sprintf(`SELECT id, competition_id, user_id, score, rank, status, submission_id, metadata, created_at, updated_at
|
||||
FROM results %s ORDER BY score DESC, created_at ASC LIMIT $%d OFFSET $%d`, where, argId, argId+1)
|
||||
query := fmt.Sprintf(
|
||||
`SELECT id, competition_id, user_id, score, rank, status, submission_id, metadata, created_at, updated_at
|
||||
FROM results %s ORDER BY score DESC, created_at ASC LIMIT $%d OFFSET $%d`,
|
||||
where,
|
||||
argId,
|
||||
argId+1,
|
||||
)
|
||||
args = append(args, opts.PageSize, opts.Page*opts.PageSize)
|
||||
|
||||
rows, err := r.db.QueryContext(ctx, query, args...)
|
||||
@@ -299,7 +305,11 @@ func (r *ResultRepository) List(ctx context.Context, opts repository.ListResults
|
||||
return results, total, nil
|
||||
}
|
||||
|
||||
func (r *ResultRepository) GetByCompetitionAndUser(ctx context.Context, competitionID uuid.UUID, userID uuid.UUID) (*domain.Result, error) {
|
||||
func (r *ResultRepository) GetByCompetitionAndUser(
|
||||
ctx context.Context,
|
||||
competitionID uuid.UUID,
|
||||
userID uuid.UUID,
|
||||
) (*domain.Result, error) {
|
||||
query := `SELECT id, competition_id, user_id, score, rank, status, submission_id, metadata, created_at, updated_at
|
||||
FROM results WHERE competition_id = $1 AND user_id = $2`
|
||||
row := r.db.QueryRowContext(ctx, query, competitionID, userID)
|
||||
@@ -334,7 +344,12 @@ func (r *ResultRepository) GetByCompetitionAndUser(ctx context.Context, competit
|
||||
return &result, nil
|
||||
}
|
||||
|
||||
func (r *ResultRepository) GetLeaderboard(ctx context.Context, competitionID uuid.UUID, limit int, offset int) ([]domain.Result, int, error) {
|
||||
func (r *ResultRepository) GetLeaderboard(
|
||||
ctx context.Context,
|
||||
competitionID uuid.UUID,
|
||||
limit int,
|
||||
offset int,
|
||||
) ([]domain.Result, int, error) {
|
||||
if r.cacheEnabled {
|
||||
key := r.leaderboardCacheKey(competitionID, limit, offset)
|
||||
val, err := r.redisClient.Get(ctx, key).Result()
|
||||
@@ -404,7 +419,11 @@ func (r *ResultRepository) GetLeaderboard(ctx context.Context, competitionID uui
|
||||
return results, total, nil
|
||||
}
|
||||
|
||||
func (r *ResultRepository) UpdateStatus(ctx context.Context, id uuid.UUID, status domain.ResultStatus) (*domain.Result, error) {
|
||||
func (r *ResultRepository) UpdateStatus(
|
||||
ctx context.Context,
|
||||
id uuid.UUID,
|
||||
status domain.ResultStatus,
|
||||
) (*domain.Result, error) {
|
||||
query := `UPDATE results SET status = $1, updated_at = $2 WHERE id = $3`
|
||||
now := time.Now()
|
||||
res, err := r.db.ExecContext(ctx, query, status, now, id)
|
||||
|
||||
@@ -2,6 +2,7 @@ package repository
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"datarush/internal/results/domain"
|
||||
|
||||
"github.com/google/uuid"
|
||||
@@ -27,4 +28,4 @@ type ResultRepository interface {
|
||||
GetLeaderboard(ctx context.Context, competitionID uuid.UUID, limit int, offset int) ([]domain.Result, int, error)
|
||||
UpdateStatus(ctx context.Context, id uuid.UUID, status domain.ResultStatus) (*domain.Result, error)
|
||||
RecalculateRanks(ctx context.Context, competitionID uuid.UUID) error
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user