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:
@@ -343,7 +343,7 @@ const docTemplate = `{
|
|||||||
"multipart/form-data"
|
"multipart/form-data"
|
||||||
],
|
],
|
||||||
"produces": [
|
"produces": [
|
||||||
"text/plain"
|
"application/json"
|
||||||
],
|
],
|
||||||
"tags": [
|
"tags": [
|
||||||
"Profile"
|
"Profile"
|
||||||
@@ -362,7 +362,7 @@ const docTemplate = `{
|
|||||||
"200": {
|
"200": {
|
||||||
"description": "Uploaded image url",
|
"description": "Uploaded image url",
|
||||||
"schema": {
|
"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": {
|
"models.ChangePasswordRequest": {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"required": [
|
"required": [
|
||||||
|
|||||||
@@ -339,7 +339,7 @@
|
|||||||
"multipart/form-data"
|
"multipart/form-data"
|
||||||
],
|
],
|
||||||
"produces": [
|
"produces": [
|
||||||
"text/plain"
|
"application/json"
|
||||||
],
|
],
|
||||||
"tags": [
|
"tags": [
|
||||||
"Profile"
|
"Profile"
|
||||||
@@ -358,7 +358,7 @@
|
|||||||
"200": {
|
"200": {
|
||||||
"description": "Uploaded image url",
|
"description": "Uploaded image url",
|
||||||
"schema": {
|
"schema": {
|
||||||
"type": "string"
|
"$ref": "#/definitions/dto.UrlDto"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -546,6 +546,17 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"dto.UrlDto": {
|
||||||
|
"type": "object",
|
||||||
|
"required": [
|
||||||
|
"url"
|
||||||
|
],
|
||||||
|
"properties": {
|
||||||
|
"url": {
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
"models.ChangePasswordRequest": {
|
"models.ChangePasswordRequest": {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"required": [
|
"required": [
|
||||||
|
|||||||
@@ -34,6 +34,13 @@ definitions:
|
|||||||
hide_profile_details:
|
hide_profile_details:
|
||||||
type: boolean
|
type: boolean
|
||||||
type: object
|
type: object
|
||||||
|
dto.UrlDto:
|
||||||
|
properties:
|
||||||
|
url:
|
||||||
|
type: string
|
||||||
|
required:
|
||||||
|
- url
|
||||||
|
type: object
|
||||||
models.ChangePasswordRequest:
|
models.ChangePasswordRequest:
|
||||||
properties:
|
properties:
|
||||||
old_password:
|
old_password:
|
||||||
@@ -394,12 +401,12 @@ paths:
|
|||||||
required: true
|
required: true
|
||||||
type: file
|
type: file
|
||||||
produces:
|
produces:
|
||||||
- text/plain
|
- application/json
|
||||||
responses:
|
responses:
|
||||||
"200":
|
"200":
|
||||||
description: Uploaded image url
|
description: Uploaded image url
|
||||||
schema:
|
schema:
|
||||||
type: string
|
$ref: '#/definitions/dto.UrlDto'
|
||||||
security:
|
security:
|
||||||
- JWT: []
|
- JWT: []
|
||||||
summary: Upload an avatar
|
summary: Upload an avatar
|
||||||
|
|||||||
@@ -89,6 +89,7 @@ func NewProfileController(_log *zap.Logger, _ps services.ProfileService) Control
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// XXX: untested
|
||||||
// @Summary Get your profile
|
// @Summary Get your profile
|
||||||
// @Tags Profile
|
// @Tags Profile
|
||||||
// @Accept json
|
// @Accept json
|
||||||
@@ -107,6 +108,7 @@ func (ctrl *ProfileController) getMyProfile(c *gin.Context) {
|
|||||||
c.JSON(http.StatusOK, response)
|
c.JSON(http.StatusOK, response)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// XXX: untested
|
||||||
// @Summary Get profile by username
|
// @Summary Get profile by username
|
||||||
// @Tags Profile
|
// @Tags Profile
|
||||||
// @Accept json
|
// @Accept json
|
||||||
@@ -142,6 +144,7 @@ func (ctrl *ProfileController) getProfileByUsername(c *gin.Context) {
|
|||||||
panic("Not implemented")
|
panic("Not implemented")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// XXX: untested
|
||||||
// @Summary Get your profile settings
|
// @Summary Get your profile settings
|
||||||
// @Tags Profile
|
// @Tags Profile
|
||||||
// @Accept json
|
// @Accept json
|
||||||
@@ -160,6 +163,7 @@ func (ctrl *ProfileController) getProfileSettings(c *gin.Context) {
|
|||||||
c.JSON(http.StatusOK, response)
|
c.JSON(http.StatusOK, response)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// XXX: untested
|
||||||
// @Summary Update your profile
|
// @Summary Update your profile
|
||||||
// @Tags Profile
|
// @Tags Profile
|
||||||
// @Accept json
|
// @Accept json
|
||||||
@@ -181,6 +185,7 @@ func (ctrl *ProfileController) updateProfile(c *gin.Context) {
|
|||||||
c.JSON(http.StatusOK, response)
|
c.JSON(http.StatusOK, response)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// XXX: untested
|
||||||
// @Summary Update your profile's settings
|
// @Summary Update your profile's settings
|
||||||
// @Tags Profile
|
// @Tags Profile
|
||||||
// @Accept json
|
// @Accept json
|
||||||
@@ -202,13 +207,14 @@ func (ctrl *ProfileController) updateProfileSettings(c *gin.Context) {
|
|||||||
c.JSON(http.StatusOK, response)
|
c.JSON(http.StatusOK, response)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// XXX: untested
|
||||||
// @Summary Upload an avatar
|
// @Summary Upload an avatar
|
||||||
// @Tags Profile
|
// @Tags Profile
|
||||||
// @Accept mpfd
|
// @Accept mpfd
|
||||||
// @Produce plain
|
// @Produce json
|
||||||
// @Security JWT
|
// @Security JWT
|
||||||
// @Param file formData file true "Avatar image file"
|
// @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]
|
// @Router /profile/avatar [post]
|
||||||
func (ctrl *ProfileController) uploadAvatar(c *gin.Context) {
|
func (ctrl *ProfileController) uploadAvatar(c *gin.Context) {
|
||||||
cinfo := GetClientInfo(c)
|
cinfo := GetClientInfo(c)
|
||||||
@@ -228,5 +234,5 @@ func (ctrl *ProfileController) uploadAvatar(c *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
c.String(http.StatusOK, link)
|
c.JSON(http.StatusOK, dto.UrlDto{Url: link})
|
||||||
}
|
}
|
||||||
|
|||||||
22
backend/internal/dto/general.go
Normal file
22
backend/internal/dto/general.go
Normal 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"`
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user