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(user): add the API for get staff
LinkinStars7d75f2fa9756
diff --git a/internal/controller/user_controller.go b/internal/controller/user_controller.goindex b35a557b..20fc68ec 100644--- a/internal/controller/user_controller.go+++ b/internal/controller/user_controller.go@@ -644,6 +644,26 @@ func (uc *UserController) UserRanking(ctx *gin.Context) {handler.HandleResponse(ctx, err, resp)}+// UserStaff get user staff+// @Summary get user staff+// @Description get user staff+// @Tags User+// @Accept json+// @Produce json+// @Security ApiKeyAuth+// @Param data body schema.GetUserStaffReq true "GetUserStaffReq"+// @Success 200 {object} handler.RespBody{data=schema.GetUserStaffResp}+// @Router /answer/api/v1/user/staff [get]+func (uc *UserController) UserStaff(ctx *gin.Context) {+ req := &schema.GetUserStaffReq{}+ if handler.BindAndCheck(ctx, req) {+ return+ }++ resp, err := uc.userService.GetUserStaff(ctx, req)+ handler.HandleResponse(ctx, err, resp)+}+// UserUnsubscribeNotification unsubscribe notification// @Summary unsubscribe notification// @Description unsubscribe notificationdiff --git a/internal/repo/user/user_repo.go b/internal/repo/user/user_repo.goindex 628394cf..568ebf90 100644--- a/internal/repo/user/user_repo.go+++ b/internal/repo/user/user_repo.go@@ -246,12 +246,16 @@ func (ur *userRepo) GetUserCount(ctx context.Context) (count int64, err error) {return count, nil}-func (ur *userRepo) SearchUserListByName(ctx context.Context, name string, limit int) (userList []*entity.User, err error) {+func (ur *userRepo) SearchUserListByName(ctx context.Context, name string, limit int,+ onlyStaff bool) (userList []*entity.User, err error) {userList = make([]*entity.User, 0)session := ur.data.DB.Context(ctx)+ if onlyStaff {+ session.Join("INNER", "user_role_rel", "`user`.id = `user_role_rel`.user_id AND `user_role_rel`.role_id > 1")+ }session.Where("status = ?", entity.UserStatusAvailable)session.Where("username LIKE ? OR display_name LIKE ?", strings.ToLower(name)+"%", name+"%")- session.OrderBy("username ASC, id DESC")+ session.OrderBy("username ASC, `user`.id DESC")session.Limit(limit)err = session.Find(&userList)if err != nil {diff --git a/internal/router/answer_api_router.go b/internal/router/answer_api_router.goindex de5cf83f..40a5bba3 100644--- a/internal/router/answer_api_router.go+++ b/internal/router/answer_api_router.go@@ -145,6 +145,7 @@ func (a *AnswerAPIRouter) RegisterUnAuthAnswerAPIRouter(r *gin.RouterGroup) {// userr.GET("/personal/user/info", a.userController.GetOtherUserInfoByUsername)r.GET("/user/ranking", a.userController.UserRanking)+ r.GET("/user/staff", a.userController.UserStaff)// answerr.GET("/answer/info", a.answerController.Get)diff --git a/internal/schema/user_schema.go b/internal/schema/user_schema.goindex 016fd1eb..13971708 100644--- a/internal/schema/user_schema.go+++ b/internal/schema/user_schema.go@@ -412,3 +412,19 @@ type UserUnsubscribeNotificationReq struct {Code string `validate:"required,gt=0,lte=500" json:"code"`Content string `json:"-"`}++// GetUserStaffReq get user staff request+type GetUserStaffReq struct {+ Username string `validate:"omitempty,gt=0,lte=500" form:"username"`+ PageSize int `validate:"omitempty,min=1" form:"page_size"`+}++// GetUserStaffResp get user staff response+type GetUserStaffResp struct {+ // username+ Username string `json:"username"`+ // display name+ DisplayName string `json:"display_name"`+ // avatar+ Avatar string `json:"avatar"`+}diff --git a/internal/service/content/user_service.go b/internal/service/content/user_service.goindex 4c9843a3..a2b33005 100644--- a/internal/service/content/user_service.go+++ b/internal/service/content/user_service.go@@ -741,6 +741,24 @@ func (us *UserService) UserRanking(ctx context.Context) (resp *schema.UserRankinreturn us.warpStatRankingResp(userInfoMapping, rankStat, voteStat, userRoleRels), nil}+// GetUserStaff get user staff+func (us *UserService) GetUserStaff(ctx context.Context, req *schema.GetUserStaffReq) (+ resp []*schema.GetUserStaffResp, err error) {+ userList, err := us.userRepo.SearchUserListByName(ctx, req.Username, req.PageSize, true)+ if err != nil {+ return nil, err+ }+ avatarMapping := us.siteInfoService.FormatListAvatar(ctx, userList)+ for _, u := range userList {+ resp = append(resp, &schema.GetUserStaffResp{+ Username: u.Username,+ DisplayName: u.DisplayName,+ Avatar: avatarMapping[u.ID].GetURL(),+ })+ }+ return resp, nil+}+// UserUnsubscribeNotification user unsubscribe email notificationfunc (us *UserService) UserUnsubscribeNotification(ctx context.Context, req *schema.UserUnsubscribeNotificationReq) (err error) {@@ -858,7 +876,7 @@ func (us *UserService) SearchUserListByName(ctx context.Context, req *schema.Getif len(req.Username) == 0 {return resp, nil}- userList, err := us.userRepo.SearchUserListByName(ctx, req.Username, 5)+ userList, err := us.userRepo.SearchUserListByName(ctx, req.Username, 5, false)if err != nil {return resp, err}diff --git a/internal/service/user_common/user.go b/internal/service/user_common/user.goindex 334bcc4e..5e1a4830 100644--- a/internal/service/user_common/user.go+++ b/internal/service/user_common/user.go@@ -21,9 +21,10 @@ package usercommonimport ("context"+ "strings"+"github.com/apache/incubator-answer/internal/base/constant""github.com/apache/incubator-answer/pkg/converter"- "strings""github.com/Chain-Zhang/pinyin""github.com/apache/incubator-answer/internal/base/reason"@@ -57,7 +58,7 @@ type UserRepo interface {GetByUsernames(ctx context.Context, usernames []string) ([]*entity.User, error)GetByEmail(ctx context.Context, email string) (userInfo *entity.User, exist bool, err error)GetUserCount(ctx context.Context) (count int64, err error)- SearchUserListByName(ctx context.Context, name string, limit int) (userList []*entity.User, err error)+ SearchUserListByName(ctx context.Context, name string, limit int, onlyStaff bool) (userList []*entity.User, err error)}// UserCommon user service