woj-server/internal/api/user/profile.go
Paul Pan d42ee0ce54 feat: a big update
1. merge woj-runner scripts into woj-server
2. add woj-runner app
3. refactor submission status problem ...
4. jwt middleware update

Co-authored-by: cxy004 <cxy004@qq.com>
Co-authored-by: wzt <w.zhongtao@qq.com>
2022-10-22 17:38:39 +08:00

53 lines
1.2 KiB
Go

package user
import (
"github.com/WHUPRJ/woj-server/internal/e"
"github.com/WHUPRJ/woj-server/internal/global"
"github.com/WHUPRJ/woj-server/internal/model"
"github.com/gin-gonic/gin"
)
type profileRequest struct {
UID uint `form:"uid"`
}
// Profile
// @Summary profile
// @Description fetch user profile
// @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.(*global.Claim).UID
role := claim.(*global.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)
e.Pong(c, status, user)
return
}