55 lines
1.2 KiB
Go
55 lines
1.2 KiB
Go
package user
|
|
|
|
import (
|
|
"git.0x7f.app/WOJ/woj-server/internal/e"
|
|
"git.0x7f.app/WOJ/woj-server/internal/model"
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
type profileRequest struct {
|
|
UID uint `form:"uid"`
|
|
}
|
|
|
|
// Profile
|
|
// @Summary profile
|
|
// @Description fetch user profile
|
|
// @Tags user
|
|
// @Accept application/x-www-form-urlencoded
|
|
// @Produce json
|
|
// @Param uid formData int false "user id"
|
|
// @Response 200 {object} e.Response "user info"
|
|
// @Security Authentication
|
|
// @Router /v1/user/profile [post]
|
|
func (h *handler) Profile(c *gin.Context) {
|
|
// TODO: create a new struct for profile (user info & solve info)
|
|
|
|
claim, exist := c.Get("claim")
|
|
if !exist {
|
|
e.Pong(c, e.UserUnauthenticated, nil)
|
|
return
|
|
}
|
|
|
|
uid := claim.(*model.Claim).UID
|
|
role := claim.(*model.Claim).Role
|
|
|
|
req := new(profileRequest)
|
|
|
|
if err := c.ShouldBind(req); err != nil {
|
|
e.Pong(c, e.InvalidParameter, nil)
|
|
return
|
|
}
|
|
|
|
if req.UID == 0 {
|
|
req.UID = uid
|
|
} else if req.UID != uid && role < model.RoleGeneral {
|
|
e.Pong(c, e.UserUnauthorized, nil)
|
|
return
|
|
}
|
|
|
|
user, status := h.userService.Profile(req.UID)
|
|
|
|
// TODO: >= admin can see is_enable
|
|
|
|
e.Pong(c, status, user)
|
|
}
|