Skip to content

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.

update invite user

aichy126144caea4f994
diff --git a/docs/docs.go b/docs/docs.go
index d2fe7190..77a19c21 100644
--- a/docs/docs.go
+++ b/docs/docs.go
@@ -5103,6 +5103,55 @@ const docTemplate = `{
}
}
},
+ "/answer/api/v1/user/info/search": {
+ "get": {
+ "security": [
+ {
+ "ApiKeyAuth": []
+ }
+ ],
+ "description": "SearchUserListByName",
+ "consumes": [
+ "application/json"
+ ],
+ "produces": [
+ "application/json"
+ ],
+ "tags": [
+ "User"
+ ],
+ "summary": "SearchUserListByName",
+ "parameters": [
+ {
+ "type": "string",
+ "description": "username",
+ "name": "username",
+ "in": "query",
+ "required": true
+ }
+ ],
+ "responses": {
+ "200": {
+ "description": "OK",
+ "schema": {
+ "allOf": [
+ {
+ "$ref": "#/definitions/handler.RespBody"
+ },
+ {
+ "type": "object",
+ "properties": {
+ "data": {
+ "$ref": "#/definitions/schema.GetOtherUserInfoResp"
+ }
+ }
+ }
+ ]
+ }
+ }
+ }
+ }
+ },
"/answer/api/v1/user/interface": {
"put": {
"security": [
diff --git a/docs/swagger.json b/docs/swagger.json
index 3a1afb34..31fdf372 100644
--- a/docs/swagger.json
+++ b/docs/swagger.json
@@ -5091,6 +5091,55 @@
}
}
},
+ "/answer/api/v1/user/info/search": {
+ "get": {
+ "security": [
+ {
+ "ApiKeyAuth": []
+ }
+ ],
+ "description": "SearchUserListByName",
+ "consumes": [
+ "application/json"
+ ],
+ "produces": [
+ "application/json"
+ ],
+ "tags": [
+ "User"
+ ],
+ "summary": "SearchUserListByName",
+ "parameters": [
+ {
+ "type": "string",
+ "description": "username",
+ "name": "username",
+ "in": "query",
+ "required": true
+ }
+ ],
+ "responses": {
+ "200": {
+ "description": "OK",
+ "schema": {
+ "allOf": [
+ {
+ "$ref": "#/definitions/handler.RespBody"
+ },
+ {
+ "type": "object",
+ "properties": {
+ "data": {
+ "$ref": "#/definitions/schema.GetOtherUserInfoResp"
+ }
+ }
+ }
+ ]
+ }
+ }
+ }
+ }
+ },
"/answer/api/v1/user/interface": {
"put": {
"security": [
diff --git a/docs/swagger.yaml b/docs/swagger.yaml
index b73f8efe..b3ef8a9d 100644
--- a/docs/swagger.yaml
+++ b/docs/swagger.yaml
@@ -5364,6 +5364,34 @@ paths:
summary: UserUpdateInfo update user info
tags:
- User
+ /answer/api/v1/user/info/search:
+ get:
+ consumes:
+ - application/json
+ description: SearchUserListByName
+ parameters:
+ - description: username
+ in: query
+ name: username
+ required: true
+ type: string
+ produces:
+ - application/json
+ responses:
+ "200":
+ description: OK
+ schema:
+ allOf:
+ - $ref: '#/definitions/handler.RespBody'
+ - properties:
+ data:
+ $ref: '#/definitions/schema.GetOtherUserInfoResp'
+ type: object
+ security:
+ - ApiKeyAuth: []
+ summary: SearchUserListByName
+ tags:
+ - User
/answer/api/v1/user/interface:
put:
consumes:
diff --git a/internal/controller/user_controller.go b/internal/controller/user_controller.go
index 5266e66b..4fbf0482 100644
--- a/internal/controller/user_controller.go
+++ b/internal/controller/user_controller.go
@@ -607,3 +607,22 @@ func (uc *UserController) UserUnsubscribeEmailNotification(ctx *gin.Context) {
err := uc.userService.UserUnsubscribeEmailNotification(ctx, req)
handler.HandleResponse(ctx, err, nil)
}
+
+// SearchUserListByName godoc
+// @Summary SearchUserListByName
+// @Description SearchUserListByName
+// @Tags User
+// @Accept json
+// @Produce json
+// @Security ApiKeyAuth
+// @Param username query string true "username"
+// @Success 200 {object} handler.RespBody{data=schema.GetOtherUserInfoResp}
+// @Router /answer/api/v1/user/info/search [get]
+func (uc *UserController) SearchUserListByName(ctx *gin.Context) {
+ req := &schema.GetOtherUserInfoByUsernameReq{}
+ if handler.BindAndCheck(ctx, req) {
+ return
+ }
+ resp, err := uc.userService.SearchUserListByName(ctx, req.Username)
+ handler.HandleResponse(ctx, err, resp)
+}
diff --git a/internal/repo/user/user_repo.go b/internal/repo/user/user_repo.go
index b26bcaa1..9fd52702 100644
--- a/internal/repo/user/user_repo.go
+++ b/internal/repo/user/user_repo.go
@@ -226,6 +226,22 @@ func (ur *userRepo) GetUserCount(ctx context.Context) (count int64, err error) {
return
}
+func (ur *userRepo) SearchUserListByName(ctx context.Context, name string) (userList []*entity.User, err error) {
+ userList = make([]*entity.User, 0)
+ if name == "" {
+ return userList, nil
+ }
+ session := ur.data.DB.Where("")
+ session.Where("username LIKE LOWER(?) or display_name LIKE ?", name+"%", name+"%").And("status =?", entity.UserStatusAvailable)
+ session.Asc("username")
+ session = session.Limit(5, 0)
+ err = session.OrderBy("id desc").Find(&userList)
+ if err != nil {
+ err = errors.InternalServer(reason.DatabaseError).WithError(err).WithStack()
+ }
+ return
+}
+
func tryToDecorateUserInfoFromUserCenter(ctx context.Context, data *data.Data, original *entity.User) (err error) {
if original == nil {
return nil
diff --git a/internal/router/answer_api_router.go b/internal/router/answer_api_router.go
index a7c2dab9..5c3f60d6 100644
--- a/internal/router/answer_api_router.go
+++ b/internal/router/answer_api_router.go
@@ -112,6 +112,7 @@ func (a *AnswerAPIRouter) RegisterMustUnAuthAnswerAPIRouter(r *gin.RouterGroup)
routerGroup.POST("/user/password/reset", a.userController.RetrievePassWord)
routerGroup.POST("/user/password/replacement", a.userController.UseRePassWord)
routerGroup.PUT("/user/email/notification", a.userController.UserUnsubscribeEmailNotification)
+ routerGroup.GET("/user/info/search", a.userController.SearchUserListByName)
}
func (a *AnswerAPIRouter) RegisterUnAuthAnswerAPIRouter(r *gin.RouterGroup) {
diff --git a/internal/service/user_common/user.go b/internal/service/user_common/user.go
index 54f4bf64..b6331e70 100644
--- a/internal/service/user_common/user.go
+++ b/internal/service/user_common/user.go
@@ -35,6 +35,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) (userList []*entity.User, err error)
}
// UserCommon user service
diff --git a/internal/service/user_service.go b/internal/service/user_service.go
index 00e6b191..c6ca63c2 100644
--- a/internal/service/user_service.go
+++ b/internal/service/user_service.go
@@ -814,6 +814,19 @@ func (us *UserService) getUserInfoMapping(ctx context.Context, userIDs []string)
return userInfoMapping, nil
}
+func (us *UserService) SearchUserListByName(ctx context.Context, name string) ([]*schema.UserBasicInfo, error) {
+ userinfolist := make([]*schema.UserBasicInfo, 0)
+ list, err := us.userRepo.SearchUserListByName(ctx, name)
+ if err != nil {
+ return userinfolist, err
+ }
+ for _, user := range list {
+ userinfo := us.userCommonService.FormatUserBasicInfo(ctx, user)
+ userinfolist = append(userinfolist, userinfo)
+ }
+ return userinfolist, nil
+}
+
func (us *UserService) warpStatRankingResp(
userInfoMapping map[string]*entity.User,
rankStat []*entity.ActivityUserRankStat,