diff --git a/.gitattributes b/.gitattributes index 7bc095762..8e7999492 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,19 +1,19 @@ -* text=auto -docs/* linguist-documentation -go.sum linguist-generated merge=ours -go.mod linguist-generated +* text=auto eol=lf +docs/* linguist-documentation eol=lf +go.sum linguist-generated merge=ours eol=lf +go.mod linguist-generated eol=lf -/.github export-ignore -.gitattributes export-ignore -.gitignore export-ignore +/.github export-ignore eol=lf +.gitattributes export-ignore eol=lf +.gitignore export-ignore eol=lf /frontend/src/icons/* binary /frontend/src/fonts/* binary -*.js text -*.json text -*.ts text -*.md text -*.yml text +*.js text eol=lf +*.json text eol=lf +*.ts text eol=lf +*.md text eol=lf +*.yml text eol=lf *.dem binary *.png binary diff --git a/internal/domain/speedruns.go b/internal/domain/speedruns.go index fe0e1cae2..34b38b031 100644 --- a/internal/domain/speedruns.go +++ b/internal/domain/speedruns.go @@ -43,7 +43,7 @@ type Speedrun struct { MapName string `json:"map_name"` PointCaptures []SpeedrunPointCaptures `json:"point_captures"` Players []SpeedrunParticipant `json:"players"` - Duration time.Duration `json:"duration"` + Duration int `json:"duration"` PlayerCount int `json:"player_count"` HostAddr string `json:"host_addr"` BotCount int `json:"bot_count"` @@ -52,7 +52,7 @@ type Speedrun struct { } func (sr Speedrun) AsDuration() time.Duration { - return time.Duration(sr.Duration) * time.Second + return time.Duration(sr.Duration) * time.Millisecond } type SpeedrunParticipant struct { diff --git a/internal/srcds/speedruns_repository.go b/internal/srcds/speedruns_repository.go index d1c4c67c1..fafea1cf8 100644 --- a/internal/srcds/speedruns_repository.go +++ b/internal/srcds/speedruns_repository.go @@ -2,7 +2,7 @@ package srcds import ( "context" - "errors" + "github.com/jackc/pgx/v5" "github.com/leighmacdonald/gbans/internal/database" "github.com/leighmacdonald/gbans/internal/domain" @@ -17,7 +17,7 @@ type speedrunRepository struct { } func (r *speedrunRepository) Save(ctx context.Context, details *domain.Speedrun) error { - return r.db.WrapTx(ctx, func(tx pgx.Tx) error { + return r.db.WrapTx(ctx, func(txFunc pgx.Tx) error { query, args, errQuery := r.db.Builder(). Insert("speedrun"). SetMap(map[string]interface{}{ @@ -34,15 +34,15 @@ func (r *speedrunRepository) Save(ctx context.Context, details *domain.Speedrun) return r.db.DBErr(errQuery) } - if errScan := tx.QueryRow(ctx, query, args...).Scan(&details.SpeedrunID); errScan != nil { + if errScan := txFunc.QueryRow(ctx, query, args...).Scan(&details.SpeedrunID); errScan != nil { return r.db.DBErr(errScan) } - if errRounds := r.insertRounds(ctx, tx, details.SpeedrunID, details.PointCaptures); errRounds != nil { + if errRounds := r.insertRounds(ctx, txFunc, details.SpeedrunID, details.PointCaptures); errRounds != nil { return errRounds } - if errPlayers := r.insertPlayers(ctx, tx, details.SpeedrunID, details.Players); errPlayers != nil { + if errPlayers := r.insertPlayers(ctx, txFunc, details.SpeedrunID, details.Players); errPlayers != nil { return errPlayers } @@ -50,7 +50,7 @@ func (r *speedrunRepository) Save(ctx context.Context, details *domain.Speedrun) }) } -func (r *speedrunRepository) insertPlayers(ctx context.Context, tx pgx.Tx, speedrunID int, players []domain.SpeedrunParticipant) error { +func (r *speedrunRepository) insertPlayers(ctx context.Context, transaction pgx.Tx, speedrunID int, players []domain.SpeedrunParticipant) error { for _, runner := range players { query, args, errQuery := r.db.Builder(). Insert("speedrun_runners"). @@ -64,7 +64,7 @@ func (r *speedrunRepository) insertPlayers(ctx context.Context, tx pgx.Tx, speed return r.db.DBErr(errQuery) } - if _, errExec := tx.Exec(ctx, query, args...); errExec != nil { + if _, errExec := transaction.Exec(ctx, query, args...); errExec != nil { return r.db.DBErr(errExec) } } @@ -72,7 +72,7 @@ func (r *speedrunRepository) insertPlayers(ctx context.Context, tx pgx.Tx, speed return nil } -func (r *speedrunRepository) insertRounds(ctx context.Context, tx pgx.Tx, speedrunID int, rounds []domain.SpeedrunPointCaptures) error { +func (r *speedrunRepository) insertRounds(ctx context.Context, transaction pgx.Tx, speedrunID int, rounds []domain.SpeedrunPointCaptures) error { for roundNum, round := range rounds { query, args, errQuery := r.db.Builder(). Insert("speedrun_rounds"). @@ -87,11 +87,11 @@ func (r *speedrunRepository) insertRounds(ctx context.Context, tx pgx.Tx, speedr return r.db.DBErr(errQuery) } - if errExec := tx.QueryRow(ctx, query, args...).Scan(&round.RoundID); errExec != nil { + if errExec := transaction.QueryRow(ctx, query, args...).Scan(&round.RoundID); errExec != nil { return r.db.DBErr(errExec) } - if errPlayers := r.insertRoundPlayers(ctx, tx, round.RoundID, round.Players); errPlayers != nil { + if errPlayers := r.insertRoundPlayers(ctx, transaction, round.RoundID, round.Players); errPlayers != nil { return errPlayers } } @@ -99,7 +99,7 @@ func (r *speedrunRepository) insertRounds(ctx context.Context, tx pgx.Tx, speedr return nil } -func (r *speedrunRepository) insertRoundPlayers(ctx context.Context, tx pgx.Tx, roundID int, players []domain.SpeedrunParticipant) error { +func (r *speedrunRepository) insertRoundPlayers(ctx context.Context, transaction pgx.Tx, roundID int, players []domain.SpeedrunParticipant) error { for _, runner := range players { query, args, errQuery := r.db.Builder(). Insert("speedrun_rounds_runners"). @@ -113,7 +113,7 @@ func (r *speedrunRepository) insertRoundPlayers(ctx context.Context, tx pgx.Tx, return r.db.DBErr(errQuery) } - if _, errExec := tx.Exec(ctx, query, args...); errExec != nil { + if _, errExec := transaction.Exec(ctx, query, args...); errExec != nil { return r.db.DBErr(errExec) } } @@ -121,6 +121,6 @@ func (r *speedrunRepository) insertRoundPlayers(ctx context.Context, tx pgx.Tx, return nil } -func (r *speedrunRepository) Query(ctx context.Context, query domain.SpeedrunQuery) ([]domain.Speedrun, error) { - return nil, errors.New("error") +func (r *speedrunRepository) Query(_ context.Context, _ domain.SpeedrunQuery) ([]domain.Speedrun, error) { + return []domain.Speedrun{}, nil } diff --git a/internal/srcds/speedruns_service.go b/internal/srcds/speedruns_service.go index 24d6f304f..004dc49ae 100644 --- a/internal/srcds/speedruns_service.go +++ b/internal/srcds/speedruns_service.go @@ -1,9 +1,10 @@ package srcds import ( + "net/http" + "github.com/gin-gonic/gin" "github.com/leighmacdonald/gbans/internal/domain" - "net/http" ) type speedrunHandler struct { @@ -23,7 +24,6 @@ func NewSpeedrunHandler(engine *gin.Engine, speedruns domain.SpeedrunUsecase, au // Groups guest.GET("/overall", handler.getOverall()) guest.GET("/map", handler.getLeaders()) - } }