added swagger
parent
e23194b71d
commit
ea00255125
14
main.go
14
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 (
|
||||
|
|
|
@ -47,7 +47,7 @@ type UserSession struct {
|
|||
CreatedAt int64
|
||||
}
|
||||
|
||||
// swagger:model UpdateUserAvatarResponse
|
||||
type UpdateUserAvatarResponse struct {
|
||||
// swagger:model UpdatedUserAvatarResponse
|
||||
type UpdatedUserAvatarResponse struct {
|
||||
AvatarUrl string
|
||||
}
|
||||
|
|
|
@ -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})
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue