From ea00255125a40fdc7feaeb2eed7bb749566136cb Mon Sep 17 00:00:00 2001 From: alex Date: Thu, 5 Jan 2023 21:22:11 +0100 Subject: [PATCH] added swagger --- main.go | 14 +++++++++++ modules/structs/user.go | 4 +-- routers/routes/v1/user/useravatar.go | 37 +++++++++++++++++++++++++--- 3 files changed, 50 insertions(+), 5 deletions(-) diff --git a/main.go b/main.go index 9cfe567..e59bdee 100644 --- a/main.go +++ b/main.go @@ -1,3 +1,17 @@ +// Package classification Click 'n' Join Storage API Documentation. +// +// Schemes: https +// Host: storage.clickandjoin.umbach.dev +// BasePath: /v1 +// Version: 0.0.1 +// +// Consumes: +// - application/json +// +// Produces: +// - application/json +// +// swagger:meta package main import ( diff --git a/modules/structs/user.go b/modules/structs/user.go index 9b3c43f..354bac0 100644 --- a/modules/structs/user.go +++ b/modules/structs/user.go @@ -47,7 +47,7 @@ type UserSession struct { CreatedAt int64 } -// swagger:model UpdateUserAvatarResponse -type UpdateUserAvatarResponse struct { +// swagger:model UpdatedUserAvatarResponse +type UpdatedUserAvatarResponse struct { AvatarUrl string } diff --git a/routers/routes/v1/user/useravatar.go b/routers/routes/v1/user/useravatar.go index 7ce1b55..382f329 100644 --- a/routers/routes/v1/user/useravatar.go +++ b/routers/routes/v1/user/useravatar.go @@ -41,6 +41,37 @@ func GetAvatar(c *fiber.Ctx) error { } func UpdateAvatar(c *fiber.Ctx) error { + // swagger:operation POST /user/avatar user userUpdateAvatar + // --- + // summary: Update avatar of a user + // consumes: + // - application/json + // produces: + // - application/json + // parameters: + // - name: X-Authorization + // in: header + // required: true + // - name: file + // in: formData + // description: New avatar + // required: true + // responses: + // '200': + // description: Updated user avatar + // schema: + // "$ref": "#/definitions/UpdatedUserAvatarResponse" + // '400': + // description: Invalid FormData + // '401': + // description: Invalid X-Authorization token + // '415': + // description: Image format is not supported + // '422': + // description: Avatar size too large + // '500': + // description: Internal server error + xAuthorization := utils.GetAuhorizationToken(c) if len(xAuthorization) != structs.LenXAuthorizationToken { @@ -53,7 +84,7 @@ func UpdateAvatar(c *fiber.Ctx) error { if err := q.GetRelease(&foundSession); err != nil { logrus.Errorln("Failed to get user session, err:", err) - return c.SendStatus(fiber.StatusInternalServerError) + return c.SendStatus(fiber.StatusUnauthorized) } file, err := c.FormFile(image.FormFileKey) @@ -86,7 +117,7 @@ func UpdateAvatar(c *fiber.Ctx) error { 40) if err != nil { - return c.SendStatus(fiber.StatusBadRequest) + return c.SendStatus(fiber.StatusInternalServerError) } avatarUrl := utils.GetUserAvatarUrl(foundSession.UserId, fileName) @@ -99,5 +130,5 @@ func UpdateAvatar(c *fiber.Ctx) error { return c.SendStatus(fiber.StatusInternalServerError) } - return c.Status(fiber.StatusOK).JSON(structs.UpdateUserAvatarResponse{AvatarUrl: avatarUrl}) + return c.Status(fiber.StatusOK).JSON(structs.UpdatedUserAvatarResponse{AvatarUrl: avatarUrl}) }