and another one
This commit is contained in:
@@ -53,7 +53,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 nil, nil if no user is found
|
||||
func GetUserByID(ctx context.Context, tx bun.Tx, id int) (*User, error) {
|
||||
return GetByID[User](tx, id).GetFirst(ctx)
|
||||
return GetByID[User](tx, id).Get(ctx)
|
||||
}
|
||||
|
||||
// GetUserByUsername queries the database for a user matching the given username
|
||||
@@ -62,7 +62,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).GetFirst(ctx)
|
||||
return GetByField[User](tx, "username", username).Get(ctx)
|
||||
}
|
||||
|
||||
// GetUserByDiscordID queries the database for a user matching the given discord id
|
||||
@@ -71,7 +71,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).GetFirst(ctx)
|
||||
return GetByField[User](tx, "discord_id", discordID).Get(ctx)
|
||||
}
|
||||
|
||||
// GetRoles loads all the roles for this user
|
||||
@@ -80,9 +80,9 @@ func (u *User) GetRoles(ctx context.Context, tx bun.Tx) ([]*Role, error) {
|
||||
return nil, errors.New("user cannot be nil")
|
||||
}
|
||||
u, err := GetByField[User](tx, "id", u.ID).
|
||||
Relation("Roles").GetFirst(ctx)
|
||||
Relation("Roles").Get(ctx)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "tx.NewSelect")
|
||||
return nil, errors.Wrap(err, "GetByField")
|
||||
}
|
||||
return u.Roles, nil
|
||||
}
|
||||
@@ -92,11 +92,11 @@ func (u *User) GetPermissions(ctx context.Context, tx bun.Tx) ([]*Permission, er
|
||||
if u == nil {
|
||||
return nil, errors.New("user cannot be nil")
|
||||
}
|
||||
permissions, err := GetByField[[]*Permission](tx, "ur.user_id", u.ID).
|
||||
return GetList[Permission](tx).
|
||||
Join("JOIN role_permissions AS rp on rp.permission_id = p.id").
|
||||
Join("JOIN user_roles AS ur ON ur.role_id = rp.role_id").
|
||||
Where("ur.user_id = ?", u.ID).
|
||||
GetAll(ctx)
|
||||
return *permissions, err
|
||||
}
|
||||
|
||||
// HasPermission checks if user has a specific permission (including wildcard check)
|
||||
@@ -139,5 +139,5 @@ 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, pageOpts, defaults).GetAll(ctx)
|
||||
return GetList[User](tx).GetPaged(ctx, pageOpts, defaults)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user