Skip to content

Commit

Permalink
Speedrun posting and re-fetching functional
Browse files Browse the repository at this point in the history
  • Loading branch information
leighmacdonald committed Jan 1, 2025
1 parent 6f6bc96 commit 7262926
Show file tree
Hide file tree
Showing 73 changed files with 1,078 additions and 653 deletions.
4 changes: 2 additions & 2 deletions go.mod

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions internal/appeal/appeal_repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func (r *appealRepository) GetAppealsByActivity(ctx context.Context, opts domain
LeftJoin("person source on source.steam_id = b.source_id").
LeftJoin("person target on target.steam_id = b.target_id")

rows, errQuery := r.db.QueryBuilder(ctx, builder)
rows, errQuery := r.db.QueryBuilder(ctx, nil, builder)
if errQuery != nil {
return nil, r.db.DBErr(errQuery)
}
Expand Down Expand Up @@ -112,7 +112,7 @@ func (r *appealRepository) updateBanMessage(ctx context.Context, message *domain
Set("message_md", message.MessageMD).
Where(sq.Eq{"ban_message_id": message.BanMessageID})

if errQuery := r.db.ExecUpdateBuilder(ctx, query); errQuery != nil {
if errQuery := r.db.ExecUpdateBuilder(ctx, nil, query); errQuery != nil {
return r.db.DBErr(errQuery)
}

Expand All @@ -128,7 +128,7 @@ func (r *appealRepository) insertBanMessage(ctx context.Context, message *domain
RETURNING ban_message_id
`

if errQuery := r.db.QueryRow(ctx, query,
if errQuery := r.db.QueryRow(ctx, nil, query,
message.BanID,
message.AuthorID.Int64(),
message.MessageMD,
Expand All @@ -152,7 +152,7 @@ func (r *appealRepository) GetBanMessages(ctx context.Context, banID int64) ([]d
Where(sq.And{sq.Eq{"a.deleted": false}, sq.Eq{"a.ban_id": banID}}).
OrderBy("a.created_on")

rows, errQuery := r.db.QueryBuilder(ctx, query)
rows, errQuery := r.db.QueryBuilder(ctx, nil, query)
if errQuery != nil {
if errors.Is(r.db.DBErr(errQuery), domain.ErrNoResult) {
return nil, nil
Expand Down Expand Up @@ -210,7 +210,7 @@ func (r *appealRepository) GetBanMessageByID(ctx context.Context, banMessageID i
message domain.BanAppealMessage
)

row, errQuery := r.db.QueryRowBuilder(ctx, query)
row, errQuery := r.db.QueryRowBuilder(ctx, nil, query)
if errQuery != nil {
return message, r.db.DBErr(errQuery)
}
Expand Down Expand Up @@ -242,7 +242,7 @@ func (r *appealRepository) DropBanMessage(ctx context.Context, message *domain.B
Set("deleted", true).
Where(sq.Eq{"ban_message_id": message.BanMessageID})

if errExec := r.db.ExecUpdateBuilder(ctx, query); errExec != nil {
if errExec := r.db.ExecUpdateBuilder(ctx, nil, query); errExec != nil {
return r.db.DBErr(errExec)
}

Expand Down
4 changes: 2 additions & 2 deletions internal/appeal/appeal_usecase.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,12 @@ func (u *appeals) CreateBanMessage(ctx context.Context, curUser domain.UserProfi
return domain.BanAppealMessage{}, domain.ErrPermissionDenied
}

_, errTarget := u.persons.GetOrCreatePersonBySteamID(ctx, bannedPerson.TargetID)
_, errTarget := u.persons.GetOrCreatePersonBySteamID(ctx, nil, bannedPerson.TargetID)
if errTarget != nil {
return domain.BanAppealMessage{}, errTarget
}

_, errSource := u.persons.GetOrCreatePersonBySteamID(ctx, bannedPerson.SourceID)
_, errSource := u.persons.GetOrCreatePersonBySteamID(ctx, nil, bannedPerson.SourceID)
if errSource != nil {
return domain.BanAppealMessage{}, errSource
}
Expand Down
10 changes: 5 additions & 5 deletions internal/asset/asset_repository_local.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func (l localRepository) Put(ctx context.Context, asset domain.Asset, body io.Re
return existing, nil
}

if errExisting != nil && !errors.Is(errExisting, domain.ErrNoResult) {
if !errors.Is(errExisting, domain.ErrNoResult) {
return domain.Asset{}, errExisting
}

Expand Down Expand Up @@ -80,7 +80,7 @@ func (l localRepository) Delete(ctx context.Context, assetID uuid.UUID) (int64,

query := l.db.Builder().Delete("asset").Where(sq.Eq{"asset_id": assetID})

if errExec := l.db.ExecDeleteBuilder(ctx, query); errExec != nil {
if errExec := l.db.ExecDeleteBuilder(ctx, nil, query); errExec != nil {
return 0, l.db.DBErr(errExec)
}

Expand Down Expand Up @@ -161,7 +161,7 @@ func (l localRepository) getAssetByUUID(ctx context.Context, assetID uuid.UUID)
authorID int64
)

if errScan := l.db.QueryRow(ctx, query, args...).
if errScan := l.db.QueryRow(ctx, nil, query, args...).
Scan(&asset.AssetID, &asset.Bucket, &authorID, &asset.MimeType, &asset.Name,
&asset.Size, &asset.Hash, &asset.CreatedOn, &asset.UpdatedOn); errScan != nil {
return domain.Asset{}, l.db.DBErr(errScan)
Expand Down Expand Up @@ -194,7 +194,7 @@ func (l localRepository) getAssetByHash(ctx context.Context, hash []byte) (domai
authorID int64
)

if errScan := l.db.QueryRow(ctx, query, args...).
if errScan := l.db.QueryRow(ctx, nil, query, args...).
Scan(&asset.AssetID, &asset.Bucket, &authorID, &asset.MimeType, &asset.Name,
&asset.Size, &asset.Hash, &asset.IsPrivate, &asset.CreatedOn, &asset.UpdatedOn); errScan != nil {
return domain.Asset{}, l.db.DBErr(errScan)
Expand Down Expand Up @@ -225,7 +225,7 @@ func (l localRepository) saveAssetToDB(ctx context.Context, asset domain.Asset)
"updated_on": asset.UpdatedOn,
})

if errInsert := l.db.ExecInsertBuilder(ctx, query); errInsert != nil {
if errInsert := l.db.ExecInsertBuilder(ctx, nil, query); errInsert != nil {
return l.db.DBErr(errInsert)
}

Expand Down
8 changes: 4 additions & 4 deletions internal/auth/auth_repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,25 +31,25 @@ func (r authRepository) SavePersonAuth(ctx context.Context, auth *domain.PersonA
return r.db.DBErr(errQuery)
}

return r.db.DBErr(r.db.QueryRow(ctx, query, args...).Scan(&auth.PersonAuthID))
return r.db.DBErr(r.db.QueryRow(ctx, nil, query, args...).Scan(&auth.PersonAuthID))
}

func (r authRepository) DeletePersonAuth(ctx context.Context, authID int64) error {
return r.db.DBErr(r.db.ExecDeleteBuilder(ctx, r.db.
return r.db.DBErr(r.db.ExecDeleteBuilder(ctx, nil, r.db.
Builder().
Delete("person_auth").
Where(sq.Eq{"person_auth_id": authID})))
}

func (r authRepository) PrunePersonAuth(ctx context.Context) error {
return r.db.DBErr(r.db.ExecDeleteBuilder(ctx, r.db.
return r.db.DBErr(r.db.ExecDeleteBuilder(ctx, nil, r.db.
Builder().
Delete("person_auth").
Where(sq.Gt{"created_on + interval '1 month'": time.Now()})))
}

func (r authRepository) GetPersonAuthByFingerprint(ctx context.Context, fingerprint string, auth *domain.PersonAuth) error {
row, errRow := r.db.QueryRowBuilder(ctx, r.db.
row, errRow := r.db.QueryRowBuilder(ctx, nil, r.db.
Builder().
Select("person_auth_id", "steam_id", "ip_addr", "refresh_token", "created_on").
From("person_auth").
Expand Down
4 changes: 2 additions & 2 deletions internal/auth/auth_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ func (h authHandler) onSteamOIDCCallback() gin.HandlerFunc {
return
}

person, errPerson := h.personUsecase.GetOrCreatePersonBySteamID(ctx, sid)
person, errPerson := h.personUsecase.GetOrCreatePersonBySteamID(ctx, nil, sid)
if errPerson != nil {
ctx.Redirect(302, referralURL)
slog.Error("Failed to create or load user profile", log.ErrAttr(errPerson), handlerName)
Expand All @@ -105,7 +105,7 @@ func (h authHandler) onSteamOIDCCallback() gin.HandlerFunc {
if errGetProfile := thirdparty.UpdatePlayerSummary(ctx, &person); errGetProfile != nil {
slog.Error("Failed to fetch user profile on login", log.ErrAttr(errGetProfile), handlerName)
} else {
if errSave := h.personUsecase.SavePerson(ctx, &person); errSave != nil {
if errSave := h.personUsecase.SavePerson(ctx, nil, &person); errSave != nil {
slog.Error("Failed to save summary update", log.ErrAttr(errSave), handlerName)
}
}
Expand Down
2 changes: 1 addition & 1 deletion internal/auth/auth_usecase.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ func (u *auth) AuthMiddleware(level domain.Privilege) gin.HandlerFunc {
return
}

loggedInPerson, errGetPerson := u.persons.GetOrCreatePersonBySteamID(ctx, sid)
loggedInPerson, errGetPerson := u.persons.GetOrCreatePersonBySteamID(ctx, nil, sid)
if errGetPerson != nil {
slog.Error("Failed to load person during auth", log.ErrAttr(errGetPerson))
ctx.AbortWithStatus(http.StatusForbidden)
Expand Down
2 changes: 1 addition & 1 deletion internal/ban/background.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func (worker *ExpirationWorker) Work(ctx context.Context, _ *river.Job[Expiratio
continue
}

person, errPerson := worker.bansPerson.GetPersonBySteamID(ctx, ban.TargetID)
person, errPerson := worker.bansPerson.GetPersonBySteamID(ctx, nil, ban.TargetID)
if errPerson != nil {
slog.Error("Failed to get expired Person", log.ErrAttr(errPerson))

Expand Down
12 changes: 6 additions & 6 deletions internal/ban/ban_asn_repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func (r banASNRepository) Expired(ctx context.Context) ([]domain.BanASN, error)

var bans []domain.BanASN

rows, errQuery := r.db.QueryBuilder(ctx, query)
rows, errQuery := r.db.QueryBuilder(ctx, nil, query)
if errQuery != nil {
return nil, r.db.DBErr(errQuery)
}
Expand Down Expand Up @@ -78,7 +78,7 @@ func (r banASNRepository) GetByASN(ctx context.Context, asNum int64, banASN *dom
)

if errQuery := r.db.
QueryRow(ctx, query, asNum).
QueryRow(ctx, nil, query, asNum).
Scan(&banASN.BanASNId, &banASN.ASNum, &banASN.Origin,
&sourceID, &targetID, &banASN.ReasonText, &banASN.ValidUntil, &banASN.CreatedOn,
&banASN.UpdatedOn, &banASN.Deleted, &banASN.Reason, &banASN.IsEnabled, &banASN.UnbanReasonText,
Expand Down Expand Up @@ -109,7 +109,7 @@ func (r banASNRepository) GetByID(ctx context.Context, banID int64) (domain.Bann
)

if errQuery := r.db.
QueryRow(ctx, query, banID).
QueryRow(ctx, nil, query, banID).
Scan(&ban.BanASNId, &ban.ASNum, &ban.Origin,
&sourceID, &targetID, &ban.ReasonText, &ban.ValidUntil, &ban.CreatedOn,
&ban.UpdatedOn, &ban.Deleted, &ban.Reason, &ban.IsEnabled, &ban.UnbanReasonText,
Expand Down Expand Up @@ -143,7 +143,7 @@ func (r banASNRepository) Get(ctx context.Context, filter domain.ASNBansQueryFil
constraints = append(constraints, sq.Eq{"b.deleted": false})
}

rows, errRows := r.db.QueryBuilder(ctx, builder.Where(constraints))
rows, errRows := r.db.QueryBuilder(ctx, nil, builder.Where(constraints))
if errRows != nil {
if errors.Is(errRows, domain.ErrNoResult) {
return []domain.BannedASNPerson{}, nil
Expand Down Expand Up @@ -198,7 +198,7 @@ func (r banASNRepository) Save(ctx context.Context, banASN *domain.BanASN) (doma
valid_until = $7, updated_on = $8, reason_text = $9, is_enabled = $10, deleted = $11,
unban_reason_text = $12, appeal_state = $13, note = $14
WHERE ban_asn_id = $1`
if err := r.db.Exec(ctx, queryUpdate, banASN.BanASNId, banASN.ASNum, banASN.Origin, banASN.SourceID.Int64(),
if err := r.db.Exec(ctx, nil, queryUpdate, banASN.BanASNId, banASN.ASNum, banASN.Origin, banASN.SourceID.Int64(),
banASN.TargetID.Int64(), banASN.Reason, banASN.ValidUntil, banASN.UpdatedOn, banASN.ReasonText, banASN.IsEnabled,
banASN.Deleted, banASN.UnbanReasonText, banASN.AppealState, banASN.Note); err != nil {
return bannedPerson, r.db.DBErr(err)
Expand All @@ -211,7 +211,7 @@ func (r banASNRepository) Save(ctx context.Context, banASN *domain.BanASN) (doma
RETURNING ban_asn_id`

if err := r.db.
QueryRow(ctx, queryInsert, banASN.ASNum, banASN.Origin, banASN.SourceID.Int64(), banASN.TargetID.Int64(),
QueryRow(ctx, nil, queryInsert, banASN.ASNum, banASN.Origin, banASN.SourceID.Int64(), banASN.TargetID.Int64(),
banASN.Reason, banASN.ValidUntil, banASN.UpdatedOn, banASN.CreatedOn, banASN.ReasonText, banASN.IsEnabled,
banASN.Deleted, banASN.UnbanReasonText, banASN.AppealState, banASN.Note).
Scan(&banASN.BanASNId); err != nil {
Expand Down
4 changes: 2 additions & 2 deletions internal/ban/ban_asn_usecase.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,12 @@ func (s banASN) Ban(ctx context.Context, req domain.RequestBanASNCreate) (domain
return ban, domain.ErrInvalidTargetSID
}

author, errAuthor := s.person.GetOrCreatePersonBySteamID(ctx, sourceID)
author, errAuthor := s.person.GetOrCreatePersonBySteamID(ctx, nil, sourceID)
if errAuthor != nil {
return ban, errors.Join(errAuthor, domain.ErrGetPerson)
}

target, errTarget := s.person.GetOrCreatePersonBySteamID(ctx, targetID)
target, errTarget := s.person.GetOrCreatePersonBySteamID(ctx, nil, targetID)
if errTarget != nil {
return ban, errors.Join(errTarget, domain.ErrGetPerson)
}
Expand Down
14 changes: 7 additions & 7 deletions internal/ban/ban_net_repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func (r banNetRepository) GetByAddress(ctx context.Context, ipAddr netip.Addr) (

var nets []domain.BanCIDR

rows, errQuery := r.db.Query(ctx, query, ipAddr.String())
rows, errQuery := r.db.Query(ctx, nil, query, ipAddr.String())
if errQuery != nil {
return nil, r.db.DBErr(errQuery)
}
Expand Down Expand Up @@ -93,7 +93,7 @@ func (r banNetRepository) Get(ctx context.Context, filter domain.CIDRBansQueryFi

var nets []domain.BannedCIDRPerson

rows, errRows := r.db.QueryBuilder(ctx, builder.Where(constraints))
rows, errRows := r.db.QueryBuilder(ctx, nil, builder.Where(constraints))
if errRows != nil {
return nil, r.db.DBErr(errRows)
}
Expand Down Expand Up @@ -154,7 +154,7 @@ func (r banNetRepository) updateBanNet(ctx context.Context, banNet *domain.BanCI
Set("appeal_state", banNet.AppealState).
Where(sq.Eq{"net_id": banNet.NetID})

return r.db.DBErr(r.db.ExecUpdateBuilder(ctx, query))
return r.db.DBErr(r.db.ExecUpdateBuilder(ctx, nil, query))
}

func (r banNetRepository) insertBanNet(ctx context.Context, banNet *domain.BanCIDR) error {
Expand All @@ -172,7 +172,7 @@ func (r banNetRepository) insertBanNet(ctx context.Context, banNet *domain.BanCI
return r.db.DBErr(errQueryArgs)
}

return r.db.DBErr(r.db.QueryRow(ctx, query, args...).Scan(&banNet.NetID))
return r.db.DBErr(r.db.QueryRow(ctx, nil, query, args...).Scan(&banNet.NetID))
}

func (r banNetRepository) Save(ctx context.Context, banNet *domain.BanCIDR) error {
Expand All @@ -189,7 +189,7 @@ func (r banNetRepository) Delete(ctx context.Context, banNet *domain.BanCIDR) er
Delete("ban_net").
Where(sq.Eq{"net_id": banNet.NetID})

if errExec := r.db.ExecDeleteBuilder(ctx, query); errExec != nil {
if errExec := r.db.ExecDeleteBuilder(ctx, nil, query); errExec != nil {
return r.db.DBErr(errExec)
}

Expand All @@ -208,7 +208,7 @@ func (r banNetRepository) Expired(ctx context.Context) ([]domain.BanCIDR, error)

var bans []domain.BanCIDR

rows, errQuery := r.db.QueryBuilder(ctx, query)
rows, errQuery := r.db.QueryBuilder(ctx, nil, query)
if errQuery != nil {
return nil, r.db.DBErr(errQuery)
}
Expand Down Expand Up @@ -259,7 +259,7 @@ func (r banNetRepository) GetByID(ctx context.Context, netID int64, banNet *doma
)

errQuery := r.db.
QueryRow(ctx, query, netID).
QueryRow(ctx, nil, query, netID).
Scan(&banNet.NetID, &cidr, &banNet.Origin,
&banNet.CreatedOn, &banNet.UpdatedOn, &banNet.Reason, &banNet.ReasonText,
&banNet.ValidUntil, &banNet.Deleted, &banNet.Note, &banNet.UnbanReasonText,
Expand Down
4 changes: 2 additions & 2 deletions internal/ban/ban_net_usecase.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,12 @@ func (s *banNet) Ban(ctx context.Context, banNet *domain.BanCIDR) error {
return errors.Join(errSaveBanNet, domain.ErrSaveBan)
}

author, errAuthor := s.persons.GetOrCreatePersonBySteamID(ctx, banNet.SourceID)
author, errAuthor := s.persons.GetOrCreatePersonBySteamID(ctx, nil, banNet.SourceID)
if errAuthor != nil {
return errors.Join(errAuthor, domain.ErrFetchSource)
}

target, errTarget := s.persons.GetOrCreatePersonBySteamID(ctx, banNet.TargetID)
target, errTarget := s.persons.GetOrCreatePersonBySteamID(ctx, nil, banNet.TargetID)
if errTarget != nil {
return errors.Join(errTarget, domain.ErrFetchTarget)
}
Expand Down
Loading

0 comments on commit 7262926

Please sign in to comment.