A Q&A platform software for teams at any scales. Whether it's a community forum, help center, or knowledge management platform, you can always count on Apache Answer.
feat: add user status api
LinkinStar5c9f0f7f7c7a
diff --git a/internal/controller/user_controller.go b/internal/controller/user_controller.goindex 8c8f6e45..168184db 100644--- a/internal/controller/user_controller.go+++ b/internal/controller/user_controller.go@@ -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 UserEmailLogindiff --git a/internal/router/answer_api_router.go b/internal/router/answer_api_router.goindex fc706223..be642844 100644--- a/internal/router/answer_api_router.go+++ b/internal/router/answer_api_router.go@@ -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)diff --git a/internal/schema/user_schema.go b/internal/schema/user_schema.goindex 73607216..f2bb5896 100644--- a/internal/schema/user_schema.go+++ b/internal/schema/user_schema.go@@ -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 responsediff --git a/internal/service/user_service.go b/internal/service/user_service.goindex dede0fd4..24d56912 100644--- a/internal/service/user_service.go+++ b/internal/service/user_service.go@@ -63,6 +63,25 @@ func (us *UserService) GetUserInfoByUserID(ctx context.Context, token, userID streturn 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)