From a27f2ad5931d1ca516ec01def624c3139ab13480 Mon Sep 17 00:00:00 2001 From: LandaMm Date: Sat, 7 Jun 2025 02:09:10 +0200 Subject: [PATCH] feat: verify user's avatar + full url for profile picture --- internal/user/routes.go | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/internal/user/routes.go b/internal/user/routes.go index 270a286..57823ef 100644 --- a/internal/user/routes.go +++ b/internal/user/routes.go @@ -180,8 +180,16 @@ func (h *UserHandler) uploadAvatar(w http.ResponseWriter, r *http.Request) { return } + if !user.AvatarVerified { + if err := h.repo.UserVerifyAvatar(r.Context(), user.ID); err != nil { + log.Println("ERR: Failed to update avatar_verified:", err) + web.Error(w, "failed to verify avatar", http.StatusInternalServerError) + return + } + } + type Response struct { - AvatarID string `json:"url"` + URL string `json:"url"` } w.Header().Set("Content-Type", "application/json") @@ -190,7 +198,7 @@ func (h *UserHandler) uploadAvatar(w http.ResponseWriter, r *http.Request) { w.Header().Set("Content-Type", "application/json") - if err := encoder.Encode(Response{AvatarID: uploadInfo.Key}); err != nil { + if err := encoder.Encode(Response{URL: fmt.Sprintf("%s/avatar/%s", h.cfg.Uri, uploadInfo.Key)}); err != nil { web.Error(w, "failed to write response", http.StatusInternalServerError) } }