add dynamic profile update, connection helper, file download metadata

- replace UserSetColor/UserSetPronouns with single UserUpdateProfile that dynamically builds one UPDATE query from UserProfileUpdateList
- add getConnectionWithResponseOnFail helper to deduplicate connection ID parsing and validation across handlers
- rename file.go to attachmentFile.go and update handler names
- GetDownloadUrlAndMetadata now fetches object metadata via StatObject and returns it alongside the presigned URL
- file download endpoint returns JSON with url and originalName
- add description field to user and DB schema
- remove unused ConnectionState variants (GroupFellow, GroupFriend)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
gitGnome
2026-04-17 13:28:27 +02:00
parent e7cf57d023
commit c85c66e43a
10 changed files with 181 additions and 104 deletions
+32 -10
View File
@@ -3,6 +3,7 @@ package postgresql
import (
"context"
"fmt"
"strings"
"time"
"go-socket/packages/cache"
@@ -33,6 +34,9 @@ func Init(ctx context.Context) {
name TEXT UNIQUE NOT NULL,
pass_hash TEXT NOT NULL,
pronouns TEXT DEFAULT NULL,
description TEXT DEFAULT NULL,
avatar TEXT DEFAULT NULL,
profileBg TEXT DEFAULT NULL,
rgba BIGINT NOT NULL DEFAULT 0 CHECK (rgba BETWEEN 0 AND 4294967295),
created_at TIMESTAMP NOT NULL DEFAULT NOW()
)
@@ -108,17 +112,35 @@ func UserGetById(ctx context.Context, user *types.User) error {
return err
}
func UserSetColor(ctx context.Context, user *types.User) error {
_, err := dbConn.Exec(ctx, `
UPDATE users SET rgba = $1 WHERE id = $2
`, convertions.RgbaToUint32(user.Color), user.Id)
return err
}
func UserUpdateProfile(ctx context.Context, user *types.User, updateList types.UserProfileUpdateList) error {
setClauses := make([]string, 0, 3)
args := make([]any, 0, 4)
argIdx := 1
func UserSetPronouns(ctx context.Context, user *types.User) error {
_, err := dbConn.Exec(ctx, `
UPDATE users SET pronouns = $1 WHERE id = $2
`, user.Pronouns, user.Id)
if updateList.Pronouns {
setClauses = append(setClauses, fmt.Sprintf("pronouns = $%d", argIdx))
args = append(args, user.Pronouns)
argIdx++
}
if updateList.Description {
setClauses = append(setClauses, fmt.Sprintf("description = $%d", argIdx))
args = append(args, user.Description)
argIdx++
}
if updateList.Color {
setClauses = append(setClauses, fmt.Sprintf("rgba = $%d", argIdx))
args = append(args, convertions.RgbaToUint32(user.Color))
argIdx++
}
if len(setClauses) == 0 {
return nil
}
query := "UPDATE users SET " + strings.Join(setClauses, ", ") + fmt.Sprintf(" WHERE id = $%d", argIdx)
args = append(args, user.Id)
_, err := dbConn.Exec(ctx, query, args...)
return err
}