Skip to content

Commit

Permalink
Fix some linter errors
Browse files Browse the repository at this point in the history
  • Loading branch information
leighmacdonald committed Dec 5, 2024
1 parent fe341c2 commit 17584cb
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 30 deletions.
24 changes: 12 additions & 12 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 2 additions & 2 deletions internal/domain/speedruns.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand All @@ -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 {
Expand Down
28 changes: 14 additions & 14 deletions internal/srcds/speedruns_repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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{}{
Expand All @@ -34,23 +34,23 @@ 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
}

return nil
})
}

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").
Expand All @@ -64,15 +64,15 @@ 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)
}
}

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").
Expand All @@ -87,19 +87,19 @@ 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
}
}

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").
Expand All @@ -113,14 +113,14 @@ 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)
}
}

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
}
4 changes: 2 additions & 2 deletions internal/srcds/speedruns_service.go
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -23,7 +24,6 @@ func NewSpeedrunHandler(engine *gin.Engine, speedruns domain.SpeedrunUsecase, au
// Groups
guest.GET("/overall", handler.getOverall())
guest.GET("/map", handler.getLeaders())

}
}

Expand Down

0 comments on commit 17584cb

Please sign in to comment.