From a7948729d5a77077ed8a788dbdd158f3417ee2fa Mon Sep 17 00:00:00 2001 From: aichy126 <16996097+aichy126@users.noreply.github.com> Date: Fri, 2 Jun 2023 15:35:20 +0800 Subject: [PATCH] update search user --- internal/controller/user_controller.go | 3 ++- internal/schema/user_schema.go | 1 + internal/service/question_service.go | 5 +---- internal/service/user_service.go | 13 ++++++++----- 4 files changed, 12 insertions(+), 10 deletions(-) diff --git a/internal/controller/user_controller.go b/internal/controller/user_controller.go index 88e57ca3..498bc356 100644 --- a/internal/controller/user_controller.go +++ b/internal/controller/user_controller.go @@ -623,6 +623,7 @@ func (uc *UserController) SearchUserListByName(ctx *gin.Context) { if handler.BindAndCheck(ctx, req) { return } - resp, err := uc.userService.SearchUserListByName(ctx, req.Username) + req.UserID = middleware.GetLoginUserIDFromContext(ctx) + resp, err := uc.userService.SearchUserListByName(ctx, req) handler.HandleResponse(ctx, err, resp) } diff --git a/internal/schema/user_schema.go b/internal/schema/user_schema.go index b1155bf4..38256b98 100644 --- a/internal/schema/user_schema.go +++ b/internal/schema/user_schema.go @@ -355,6 +355,7 @@ type UserBasicInfo struct { type GetOtherUserInfoByUsernameReq struct { Username string `validate:"required,gt=0,lte=500" form:"username"` + UserID string `json:"-"` } type GetOtherUserInfoResp struct { diff --git a/internal/service/question_service.go b/internal/service/question_service.go index 5e138428..cf46c580 100644 --- a/internal/service/question_service.go +++ b/internal/service/question_service.go @@ -567,10 +567,7 @@ func (qs *QuestionService) UpdateQuestionInviteUser(ctx context.Context, req *sc for _, item := range req.InviteUser { _, ok := inviteUserInfoList[item] if ok { - //The inviter can't be himself. - if req.UserID != inviteUserInfoList[item].ID { - inviteUserIDs = append(inviteUserIDs, inviteUserInfoList[item].ID) - } + inviteUserIDs = append(inviteUserIDs, inviteUserInfoList[item].ID) } } inviteUserStr := "" diff --git a/internal/service/user_service.go b/internal/service/user_service.go index 2fa336ef..72b4440b 100644 --- a/internal/service/user_service.go +++ b/internal/service/user_service.go @@ -817,17 +817,20 @@ func (us *UserService) getUserInfoMapping(ctx context.Context, userIDs []string) return userInfoMapping, nil } -func (us *UserService) SearchUserListByName(ctx context.Context, name string) ([]*schema.UserBasicInfo, error) { +func (us *UserService) SearchUserListByName(ctx context.Context, input *schema.GetOtherUserInfoByUsernameReq) ([]*schema.UserBasicInfo, error) { userinfolist := make([]*schema.UserBasicInfo, 0) - list, err := us.userRepo.SearchUserListByName(ctx, name) + list, err := us.userRepo.SearchUserListByName(ctx, input.Username) if err != nil { return userinfolist, err } avatarMapping := us.siteInfoService.FormatListAvatar(ctx, list) for _, user := range list { - userinfo := us.userCommonService.FormatUserBasicInfo(ctx, user) - userinfo.Avatar = avatarMapping[user.ID].GetURL() - userinfolist = append(userinfolist, userinfo) + if input.UserID != user.ID { + userinfo := us.userCommonService.FormatUserBasicInfo(ctx, user) + userinfo.Avatar = avatarMapping[user.ID].GetURL() + userinfolist = append(userinfolist, userinfo) + } + } return userinfolist, nil }