add option for avatar/profilebg change
This commit is contained in:
@@ -36,7 +36,7 @@ func Init(ctx context.Context) {
|
||||
pronouns TEXT DEFAULT NULL,
|
||||
description TEXT DEFAULT NULL,
|
||||
avatar TEXT DEFAULT NULL,
|
||||
profileBg TEXT DEFAULT NULL,
|
||||
profile_bg TEXT DEFAULT NULL,
|
||||
rgba BIGINT NOT NULL DEFAULT 0 CHECK (rgba BETWEEN 0 AND 4294967295),
|
||||
created_at TIMESTAMP NOT NULL DEFAULT NOW()
|
||||
)
|
||||
@@ -93,8 +93,8 @@ func UserDelete(ctx context.Context, id uuid.UUID) error {
|
||||
func UserGetStandardInfoByName(ctx context.Context, user *types.User) error {
|
||||
var rgba int64
|
||||
err := dbConn.QueryRow(ctx, `
|
||||
SELECT id, name, pass_hash, COALESCE(pronouns, ''), rgba, created_at FROM users WHERE name = $1
|
||||
`, user.Name).Scan(&user.Id, &user.Name, &user.PasswordHash, &user.Pronouns, &rgba, &user.CreatedAt)
|
||||
SELECT id, name, pass_hash, COALESCE(pronouns, ''), rgba, created_at, COALESCE(avatar, ''), COALESCE(profile_bg, '') FROM users WHERE name = $1
|
||||
`, user.Name).Scan(&user.Id, &user.Name, &user.PasswordHash, &user.Pronouns, &rgba, &user.CreatedAt, &user.Avatar, &user.ProfileBg)
|
||||
if err == nil {
|
||||
user.Color = convertions.Uint32ToRgba(uint32(rgba))
|
||||
}
|
||||
@@ -104,8 +104,8 @@ func UserGetStandardInfoByName(ctx context.Context, user *types.User) error {
|
||||
func UserGetById(ctx context.Context, user *types.User) error {
|
||||
var rgba int64
|
||||
err := dbConn.QueryRow(ctx, `
|
||||
SELECT name, pass_hash, COALESCE(pronouns, ''), rgba, created_at FROM users WHERE id = $1
|
||||
`, user.Id).Scan(&user.Name, &user.PasswordHash, &user.Pronouns, &rgba, &user.CreatedAt)
|
||||
SELECT name, pass_hash, COALESCE(pronouns, ''), rgba, created_at, COALESCE(avatar, ''), COALESCE(profile_bg, '') FROM users WHERE id = $1
|
||||
`, user.Id).Scan(&user.Name, &user.PasswordHash, &user.Pronouns, &rgba, &user.CreatedAt, &user.Avatar, &user.ProfileBg)
|
||||
if err == nil {
|
||||
user.Color = convertions.Uint32ToRgba(uint32(rgba))
|
||||
}
|
||||
@@ -132,6 +132,16 @@ func UserUpdateProfile(ctx context.Context, user *types.User, updateList types.U
|
||||
args = append(args, convertions.RgbaToUint32(user.Color))
|
||||
argIdx++
|
||||
}
|
||||
if updateList.Avatar {
|
||||
setClauses = append(setClauses, fmt.Sprintf("avatar = $%d", argIdx))
|
||||
args = append(args, user.Avatar)
|
||||
argIdx++
|
||||
}
|
||||
if updateList.ProfileBg {
|
||||
setClauses = append(setClauses, fmt.Sprintf("profile_bg = $%d", argIdx))
|
||||
args = append(args, user.ProfileBg)
|
||||
argIdx++
|
||||
}
|
||||
|
||||
if len(setClauses) == 0 {
|
||||
return nil
|
||||
|
||||
Reference in New Issue
Block a user