package user import ( "git.0x7f.app/WOJ/woj-server/internal/e" "git.0x7f.app/WOJ/woj-server/internal/model" "git.0x7f.app/WOJ/woj-server/pkg/utils" "github.com/gin-gonic/gin" ) type profileRequest struct { UID uint `form:"uid" json:"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[model.User] "user info" // @Security Authentication // @Router /v1/user/profile [post] func (h *handler) Profile(c *gin.Context) { claim, exist := c.Get("claim") if !exist { e.Pong[any](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, err.Error()) return } user, status := h.userService.Profile(utils.If(req.UID == 0, uid, req.UID)) if status != e.Success { e.Pong[any](c, status, nil) return } if role < model.RoleAdmin && user.ID != uid { e.Pong[any](c, e.UserUnauthorized, nil) return } e.Pong(c, status, user) }