Files
go-socket/packages/httpRequest/get.go
T
gitGnome c85c66e43a 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>
2026-04-17 13:28:27 +02:00

49 lines
1.2 KiB
Go

package httpRequest
import (
"context"
"go-socket/packages/convertions"
"net/http"
"go-socket/packages/cache"
"go-socket/packages/postgresql"
"go-socket/packages/tokens"
"go-socket/packages/types"
"github.com/google/uuid"
)
func getUserById(ctx context.Context, userId uuid.UUID) (*types.User, error) {
user, err := cache.CacheGetUserById(userId)
if err != nil {
user = &types.User{Id: userId}
err = postgresql.GetWholeUser(ctx, user)
if err != nil {
return nil, err
}
}
return user, nil
}
func getUserByToken(ctx context.Context, token string) (*types.User, error) {
userId, err := tokens.TokenValidateGetId(token)
if err != nil {
return nil, err
}
return getUserById(ctx, userId)
}
func getConnectionWithResponseOnFail(response *http.ResponseWriter, request *http.Request, user *types.User) (*types.Connection, bool) {
connectionId, err := convertions.ConvertStringUuid(request.FormValue("connectionid"))
if err != nil {
http.Error(*response, "invalid connectionid", http.StatusBadRequest)
return nil, false
}
conn, ok := cache.CacheGetConnection(user, connectionId)
if !ok {
http.Error(*response, "invalid connectionid", http.StatusBadRequest)
return nil, false
}
return conn, true
}