feat: add user status api

This commit is contained in:
LinkinStar 2022-09-28 14:22:55 +08:00
parent 9b1a175cd2
commit 5c9f0f7f7c
4 changed files with 40 additions and 0 deletions

View File

@ -80,6 +80,21 @@ func (uc *UserController) GetOtherUserInfoByUsername(ctx *gin.Context) {
handler.HandleResponse(ctx, err, resp)
}
// GetUserStatus get user status info
// @Summary get user status info
// @Description get user status info
// @Tags User
// @Accept json
// @Produce json
// @Security ApiKeyAuth
// @Success 200 {object} handler.RespBody{data=schema.GetUserResp}
// @Router /answer/api/v1/user/status [get]
func (uc *UserController) GetUserStatus(ctx *gin.Context) {
userID := middleware.GetLoginUserIDFromContext(ctx)
resp, err := uc.userService.GetUserStatus(ctx, userID)
handler.HandleResponse(ctx, err, resp)
}
// UserEmailLogin godoc
// @Summary UserEmailLogin
// @Description UserEmailLogin

View File

@ -87,6 +87,7 @@ func (a *AnswerAPIRouter) RegisterUnAuthAnswerAPIRouter(r *gin.RouterGroup) {
r.GET("/comment", a.commentController.GetComment)
// user
r.GET("/user/status", a.userController.GetUserStatus)
r.GET("/user/action/record", a.userController.ActionRecord)
r.POST("/user/login/email", a.userController.UserEmailLogin)
r.POST("/user/register/email", a.userController.UserRegisterByEmail)

View File

@ -76,7 +76,12 @@ func (r *GetUserResp) GetFromUserEntity(userInfo *entity.User) {
if ok {
r.Status = statusShow
}
}
// GetUserStatusResp get user status info
type GetUserStatusResp struct {
// user status
Status string `json:"status"`
}
// GetOtherUserInfoByUsernameResp get user response

View File

@ -63,6 +63,25 @@ func (us *UserService) GetUserInfoByUserID(ctx context.Context, token, userID st
return resp, nil
}
// GetUserStatus get user info by user id
func (us *UserService) GetUserStatus(ctx context.Context, userID string) (resp *schema.GetUserStatusResp, err error) {
resp = &schema.GetUserStatusResp{}
if len(userID) == 0 {
return resp, nil
}
userInfo, exist, err := us.userRepo.GetByUserID(ctx, userID)
if err != nil {
return nil, err
}
if !exist {
return nil, errors.BadRequest(reason.UserNotFound)
}
resp = &schema.GetUserStatusResp{
Status: schema.UserStatusShow[userInfo.Status],
}
return resp, nil
}
func (us *UserService) GetOtherUserInfoByUsername(ctx context.Context, username string) (
resp *schema.GetOtherUserInfoResp, err error) {
userInfo, exist, err := us.userRepo.GetByUsername(ctx, username)