diff --git a/backend/docs/docs.go b/backend/docs/docs.go index a5b6ba3..a72bbf8 100644 --- a/backend/docs/docs.go +++ b/backend/docs/docs.go @@ -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": [ diff --git a/backend/docs/swagger.json b/backend/docs/swagger.json index be0e835..dd6fb1f 100644 --- a/backend/docs/swagger.json +++ b/backend/docs/swagger.json @@ -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": [ diff --git a/backend/docs/swagger.yaml b/backend/docs/swagger.yaml index 8fc360a..6ee6635 100644 --- a/backend/docs/swagger.yaml +++ b/backend/docs/swagger.yaml @@ -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 diff --git a/backend/internal/controllers/profile.go b/backend/internal/controllers/profile.go index c87a159..07215b6 100644 --- a/backend/internal/controllers/profile.go +++ b/backend/internal/controllers/profile.go @@ -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}) } diff --git a/backend/internal/dto/general.go b/backend/internal/dto/general.go new file mode 100644 index 0000000..8f268d1 --- /dev/null +++ b/backend/internal/dto/general.go @@ -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 . + +package dto + +type UrlDto struct { + Url string `json:"url" binding:"required"` +}