fix: change avatar upload response to JSON object with URL;

feat: add UrlDto for standardized URL responses;
refactor: update avatar upload endpoint to return UrlDto;
docs: regenerate Swagger;
chore: add comments for untested profile controller methods
This commit is contained in:
2025-07-19 23:23:56 +03:00
parent f65439fb50
commit df54829a67
5 changed files with 66 additions and 9 deletions

View File

@@ -343,7 +343,7 @@ const docTemplate = `{
"multipart/form-data"
],
"produces": [
"text/plain"
"application/json"
],
"tags": [
"Profile"
@@ -362,7 +362,7 @@ const docTemplate = `{
"200": {
"description": "Uploaded image url",
"schema": {
"type": "string"
"$ref": "#/definitions/dto.UrlDto"
}
}
}
@@ -550,6 +550,17 @@ const docTemplate = `{
}
}
},
"dto.UrlDto": {
"type": "object",
"required": [
"url"
],
"properties": {
"url": {
"type": "string"
}
}
},
"models.ChangePasswordRequest": {
"type": "object",
"required": [

View File

@@ -339,7 +339,7 @@
"multipart/form-data"
],
"produces": [
"text/plain"
"application/json"
],
"tags": [
"Profile"
@@ -358,7 +358,7 @@
"200": {
"description": "Uploaded image url",
"schema": {
"type": "string"
"$ref": "#/definitions/dto.UrlDto"
}
}
}
@@ -546,6 +546,17 @@
}
}
},
"dto.UrlDto": {
"type": "object",
"required": [
"url"
],
"properties": {
"url": {
"type": "string"
}
}
},
"models.ChangePasswordRequest": {
"type": "object",
"required": [

View File

@@ -34,6 +34,13 @@ definitions:
hide_profile_details:
type: boolean
type: object
dto.UrlDto:
properties:
url:
type: string
required:
- url
type: object
models.ChangePasswordRequest:
properties:
old_password:
@@ -394,12 +401,12 @@ paths:
required: true
type: file
produces:
- text/plain
- application/json
responses:
"200":
description: Uploaded image url
schema:
type: string
$ref: '#/definitions/dto.UrlDto'
security:
- JWT: []
summary: Upload an avatar

View File

@@ -89,6 +89,7 @@ func NewProfileController(_log *zap.Logger, _ps services.ProfileService) Control
}
}
// XXX: untested
// @Summary Get your profile
// @Tags Profile
// @Accept json
@@ -107,6 +108,7 @@ func (ctrl *ProfileController) getMyProfile(c *gin.Context) {
c.JSON(http.StatusOK, response)
}
// XXX: untested
// @Summary Get profile by username
// @Tags Profile
// @Accept json
@@ -142,6 +144,7 @@ func (ctrl *ProfileController) getProfileByUsername(c *gin.Context) {
panic("Not implemented")
}
// XXX: untested
// @Summary Get your profile settings
// @Tags Profile
// @Accept json
@@ -160,6 +163,7 @@ func (ctrl *ProfileController) getProfileSettings(c *gin.Context) {
c.JSON(http.StatusOK, response)
}
// XXX: untested
// @Summary Update your profile
// @Tags Profile
// @Accept json
@@ -181,6 +185,7 @@ func (ctrl *ProfileController) updateProfile(c *gin.Context) {
c.JSON(http.StatusOK, response)
}
// XXX: untested
// @Summary Update your profile's settings
// @Tags Profile
// @Accept json
@@ -202,13 +207,14 @@ func (ctrl *ProfileController) updateProfileSettings(c *gin.Context) {
c.JSON(http.StatusOK, response)
}
// XXX: untested
// @Summary Upload an avatar
// @Tags Profile
// @Accept mpfd
// @Produce plain
// @Produce json
// @Security JWT
// @Param file formData file true "Avatar image file"
// @Success 200 {object} string "Uploaded image url"
// @Success 200 {object} dto.UrlDto "Uploaded image url"
// @Router /profile/avatar [post]
func (ctrl *ProfileController) uploadAvatar(c *gin.Context) {
cinfo := GetClientInfo(c)
@@ -228,5 +234,5 @@ func (ctrl *ProfileController) uploadAvatar(c *gin.Context) {
return
}
c.String(http.StatusOK, link)
c.JSON(http.StatusOK, dto.UrlDto{Url: link})
}

View File

@@ -0,0 +1,22 @@
// Copyright (c) 2025 Nikolai Papin
//
// This file is part of Easywish
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
// the GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
package dto
type UrlDto struct {
Url string `json:"url" binding:"required"`
}