2022-09-20 14:15:21 +08:00
|
|
|
package user
|
2022-09-20 15:11:37 +08:00
|
|
|
|
|
|
|
import (
|
2023-07-14 21:47:11 +08:00
|
|
|
"git.0x7f.app/WOJ/woj-server/internal/e"
|
|
|
|
"git.0x7f.app/WOJ/woj-server/internal/model"
|
2023-12-22 15:19:13 +08:00
|
|
|
"git.0x7f.app/WOJ/woj-server/pkg/utils"
|
2022-09-20 15:11:37 +08:00
|
|
|
"github.com/gin-gonic/gin"
|
|
|
|
)
|
|
|
|
|
|
|
|
type profileRequest struct {
|
2023-12-23 15:35:09 +08:00
|
|
|
UID uint `form:"uid" json:"uid"`
|
2022-09-20 15:11:37 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Profile
|
|
|
|
// @Summary profile
|
|
|
|
// @Description fetch user profile
|
2023-12-18 21:21:15 +08:00
|
|
|
// @Tags user
|
2022-09-20 15:11:37 +08:00
|
|
|
// @Accept application/x-www-form-urlencoded
|
|
|
|
// @Produce json
|
2022-09-26 16:13:31 +08:00
|
|
|
// @Param uid formData int false "user id"
|
2023-12-22 15:19:13 +08:00
|
|
|
// @Response 200 {object} e.Response[model.User] "user info"
|
2022-09-20 15:11:37 +08:00
|
|
|
// @Security Authentication
|
|
|
|
// @Router /v1/user/profile [post]
|
|
|
|
func (h *handler) Profile(c *gin.Context) {
|
|
|
|
claim, exist := c.Get("claim")
|
|
|
|
if !exist {
|
2023-12-22 15:19:13 +08:00
|
|
|
e.Pong[any](c, e.UserUnauthenticated, nil)
|
2022-09-20 15:11:37 +08:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2023-07-15 16:19:49 +08:00
|
|
|
uid := claim.(*model.Claim).UID
|
2024-03-16 22:00:37 +08:00
|
|
|
// role := claim.(*model.Claim).Role
|
2022-10-22 17:38:39 +08:00
|
|
|
|
2022-09-20 15:11:37 +08:00
|
|
|
req := new(profileRequest)
|
2022-10-22 17:38:39 +08:00
|
|
|
if err := c.ShouldBind(req); err != nil {
|
2023-12-22 15:19:13 +08:00
|
|
|
e.Pong(c, e.InvalidParameter, err.Error())
|
2022-10-22 17:38:39 +08:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2023-12-22 15:19:13 +08:00
|
|
|
user, status := h.userService.Profile(utils.If(req.UID == 0, uid, req.UID))
|
|
|
|
if status != e.Success {
|
|
|
|
e.Pong[any](c, status, nil)
|
2022-10-22 17:38:39 +08:00
|
|
|
return
|
2022-09-20 15:11:37 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
e.Pong(c, status, user)
|
|
|
|
}
|