slapid and player now links when registering

This commit is contained in:
2026-02-17 18:33:22 +11:00
parent e50f855206
commit 103da78f0b
11 changed files with 137 additions and 28 deletions

View File

@@ -56,7 +56,7 @@ func CreateUser(ctx context.Context, tx bun.Tx, username string, discorduser *di
// GetUserByID queries the database for a user matching the given ID
// Returns a BadRequestNotFound error if no user is found
func GetUserByID(ctx context.Context, tx bun.Tx, id int) (*User, error) {
return GetByID[User](tx, id).Get(ctx)
return GetByID[User](tx, id).Relation("Player").Get(ctx)
}
// GetUserByUsername queries the database for a user matching the given username
@@ -65,7 +65,7 @@ func GetUserByUsername(ctx context.Context, tx bun.Tx, username string) (*User,
if username == "" {
return nil, errors.New("username not provided")
}
return GetByField[User](tx, "username", username).Get(ctx)
return GetByField[User](tx, "username", username).Relation("Player").Get(ctx)
}
// GetUserByDiscordID queries the database for a user matching the given discord id
@@ -74,7 +74,7 @@ func GetUserByDiscordID(ctx context.Context, tx bun.Tx, discordID string) (*User
if discordID == "" {
return nil, errors.New("discord_id not provided")
}
return GetByField[User](tx, "discord_id", discordID).Get(ctx)
return GetByField[User](tx, "u.discord_id", discordID).Relation("Player").Get(ctx)
}
// GetRoles loads all the roles for this user
@@ -142,7 +142,7 @@ func (u *User) IsAdmin(ctx context.Context, tx bun.Tx) (bool, error) {
func GetUsers(ctx context.Context, tx bun.Tx, pageOpts *PageOpts) (*List[User], error) {
defaults := &PageOpts{1, 50, bun.OrderAsc, "id"}
return GetList[User](tx).GetPaged(ctx, pageOpts, defaults)
return GetList[User](tx).Relation("Player").GetPaged(ctx, pageOpts, defaults)
}
// GetUsersWithRoles queries the database for users with their roles preloaded