diff --git a/docs/docs.go b/docs/docs.go index 230932657..10453be27 100644 --- a/docs/docs.go +++ b/docs/docs.go @@ -1741,6 +1741,45 @@ const docTemplate = `{ } } }, + "/answer/admin/api/users": { + "post": { + "security": [ + { + "ApiKeyAuth": [] + } + ], + "description": "add users", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "admin" + ], + "summary": "add users", + "parameters": [ + { + "description": "user", + "name": "data", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/schema.AddUserReq" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/handler.RespBody" + } + } + } + } + }, "/answer/admin/api/users/activation": { "post": { "security": [ @@ -4515,7 +4554,39 @@ const docTemplate = `{ "type": "object", "properties": { "data": { - "$ref": "#/definitions/schema.SearchListResp" + "$ref": "#/definitions/schema.SearchResp" + } + } + } + ] + } + } + } + } + }, + "/answer/api/v1/search/desc": { + "get": { + "description": "get search description", + "produces": [ + "application/json" + ], + "tags": [ + "Search" + ], + "summary": "get search description", + "responses": { + "200": { + "description": "OK", + "schema": { + "allOf": [ + { + "$ref": "#/definitions/handler.RespBody" + }, + { + "type": "object", + "properties": { + "data": { + "$ref": "#/definitions/schema.SearchResp" } } } @@ -5406,7 +5477,7 @@ const docTemplate = `{ "in": "body", "required": true, "schema": { - "$ref": "#/definitions/schema.UserEmailLogin" + "$ref": "#/definitions/schema.UserEmailLoginReq" } } ], @@ -6346,6 +6417,13 @@ const docTemplate = `{ "original_text" ], "properties": { + "captcha_code": { + "type": "string" + }, + "captcha_id": { + "description": "captcha_id", + "type": "string" + }, "mention_username_list": { "description": "@ user id list", "type": "array", @@ -6376,6 +6454,13 @@ const docTemplate = `{ "report_type" ], "properties": { + "captcha_code": { + "type": "string" + }, + "captcha_id": { + "description": "captcha_id", + "type": "string" + }, "content": { "description": "report content", "type": "string", @@ -6480,6 +6565,12 @@ const docTemplate = `{ "content" ], "properties": { + "captcha_code": { + "type": "string" + }, + "captcha_id": { + "type": "string" + }, "content": { "type": "string", "maxLength": 65535, @@ -6496,6 +6587,12 @@ const docTemplate = `{ "content" ], "properties": { + "captcha_code": { + "type": "string" + }, + "captcha_id": { + "type": "string" + }, "content": { "type": "string", "maxLength": 65535, @@ -6926,6 +7023,7 @@ const docTemplate = `{ "type": "integer" }, "have_password": { + "description": "user have password", "type": "boolean" }, "id": { @@ -7702,6 +7800,13 @@ const docTemplate = `{ "title" ], "properties": { + "captcha_code": { + "type": "string" + }, + "captcha_id": { + "description": "captcha_id", + "type": "string" + }, "content": { "description": "content", "type": "string", @@ -7737,6 +7842,13 @@ const docTemplate = `{ "maxLength": 65535, "minLength": 6 }, + "captcha_code": { + "type": "string" + }, + "captcha_id": { + "description": "captcha_id", + "type": "string" + }, "content": { "description": "content", "type": "string", @@ -7898,6 +8010,13 @@ const docTemplate = `{ "title" ], "properties": { + "captcha_code": { + "type": "string" + }, + "captcha_id": { + "description": "captcha_id", + "type": "string" + }, "content": { "description": "content", "type": "string", @@ -7939,6 +8058,13 @@ const docTemplate = `{ "id" ], "properties": { + "captcha_code": { + "type": "string" + }, + "captcha_id": { + "description": "captcha_id", + "type": "string" + }, "id": { "type": "string" }, @@ -7956,8 +8082,13 @@ const docTemplate = `{ "id" ], "properties": { + "captcha_code": { + "type": "string" + }, + "captcha_id": { + "type": "string" + }, "id": { - "description": "answer id", "type": "string" } } @@ -7968,6 +8099,13 @@ const docTemplate = `{ "comment_id" ], "properties": { + "captcha_code": { + "type": "string" + }, + "captcha_id": { + "description": "captcha_id", + "type": "string" + }, "comment_id": { "description": "comment id", "type": "string" @@ -7980,6 +8118,13 @@ const docTemplate = `{ "id" ], "properties": { + "captcha_code": { + "type": "string" + }, + "captcha_id": { + "description": "captcha_id", + "type": "string" + }, "id": { "description": "question id", "type": "string" @@ -8041,24 +8186,6 @@ const docTemplate = `{ } } }, - "schema.SearchListResp": { - "type": "object", - "properties": { - "count": { - "type": "integer" - }, - "extra": { - "description": "extra fields" - }, - "list": { - "description": "search response", - "type": "array", - "items": { - "$ref": "#/definitions/schema.SearchResults" - } - } - } - }, "schema.SearchObject": { "type": "object", "properties": { @@ -8107,7 +8234,22 @@ const docTemplate = `{ } } }, - "schema.SearchResults": { + "schema.SearchResp": { + "type": "object", + "properties": { + "count": { + "type": "integer" + }, + "list": { + "description": "search response", + "type": "array", + "items": { + "$ref": "#/definitions/schema.SearchResult" + } + } + } + }, + "schema.SearchResult": { "type": "object", "properties": { "object": { @@ -8729,6 +8871,13 @@ const docTemplate = `{ "original_text" ], "properties": { + "captcha_code": { + "type": "string" + }, + "captcha_id": { + "description": "captcha_id", + "type": "string" + }, "comment_id": { "description": "comment id", "type": "string" @@ -9004,39 +9153,30 @@ const docTemplate = `{ "type": "object", "properties": { "avatar": { - "description": "avatar", "type": "string" }, "display_name": { - "description": "display_name", "type": "string" }, "id": { - "description": "user_id", "type": "string" }, "ip_info": { - "description": "ip info", "type": "string" }, "location": { - "description": "location", "type": "string" }, "rank": { - "description": "rank", "type": "integer" }, "status": { - "description": "status", "type": "string" }, "username": { - "description": "name", "type": "string" }, "website": { - "description": "website", "type": "string" } } @@ -9078,7 +9218,7 @@ const docTemplate = `{ } } }, - "schema.UserEmailLogin": { + "schema.UserEmailLoginReq": { "type": "object", "required": [ "e_mail", @@ -9086,20 +9226,16 @@ const docTemplate = `{ ], "properties": { "captcha_code": { - "description": "captcha_code", "type": "string" }, "captcha_id": { - "description": "captcha_id", "type": "string" }, "e_mail": { - "description": "e_mail", "type": "string", "maxLength": 500 }, "pass": { - "description": "password", "type": "string", "maxLength": 32, "minLength": 8 @@ -9309,12 +9445,10 @@ const docTemplate = `{ ], "properties": { "code": { - "description": "code", "type": "string", "maxLength": 100 }, "pass": { - "description": "Password", "type": "string", "maxLength": 32 } @@ -9329,25 +9463,20 @@ const docTemplate = `{ ], "properties": { "captcha_code": { - "description": "captcha_code", "type": "string" }, "captcha_id": { - "description": "captcha_id", "type": "string" }, "e_mail": { - "description": "email", "type": "string", "maxLength": 500 }, "name": { - "description": "name", "type": "string", "maxLength": 30 }, "pass": { - "description": "password", "type": "string", "maxLength": 32, "minLength": 8 @@ -9361,15 +9490,12 @@ const docTemplate = `{ ], "properties": { "captcha_code": { - "description": "captcha_code", "type": "string" }, "captcha_id": { - "description": "captcha_id", "type": "string" }, "e_mail": { - "description": "e_mail", "type": "string", "maxLength": 500 } @@ -9381,6 +9507,13 @@ const docTemplate = `{ "object_id" ], "properties": { + "captcha_code": { + "type": "string" + }, + "captcha_id": { + "description": "captcha_id", + "type": "string" + }, "is_cancel": { "description": "is cancel", "type": "boolean" diff --git a/docs/swagger.json b/docs/swagger.json index dc60d4715..a7a91bc95 100644 --- a/docs/swagger.json +++ b/docs/swagger.json @@ -1729,6 +1729,45 @@ } } }, + "/answer/admin/api/users": { + "post": { + "security": [ + { + "ApiKeyAuth": [] + } + ], + "description": "add users", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "admin" + ], + "summary": "add users", + "parameters": [ + { + "description": "user", + "name": "data", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/schema.AddUserReq" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/handler.RespBody" + } + } + } + } + }, "/answer/admin/api/users/activation": { "post": { "security": [ @@ -4503,7 +4542,39 @@ "type": "object", "properties": { "data": { - "$ref": "#/definitions/schema.SearchListResp" + "$ref": "#/definitions/schema.SearchResp" + } + } + } + ] + } + } + } + } + }, + "/answer/api/v1/search/desc": { + "get": { + "description": "get search description", + "produces": [ + "application/json" + ], + "tags": [ + "Search" + ], + "summary": "get search description", + "responses": { + "200": { + "description": "OK", + "schema": { + "allOf": [ + { + "$ref": "#/definitions/handler.RespBody" + }, + { + "type": "object", + "properties": { + "data": { + "$ref": "#/definitions/schema.SearchResp" } } } @@ -5394,7 +5465,7 @@ "in": "body", "required": true, "schema": { - "$ref": "#/definitions/schema.UserEmailLogin" + "$ref": "#/definitions/schema.UserEmailLoginReq" } } ], @@ -6334,6 +6405,13 @@ "original_text" ], "properties": { + "captcha_code": { + "type": "string" + }, + "captcha_id": { + "description": "captcha_id", + "type": "string" + }, "mention_username_list": { "description": "@ user id list", "type": "array", @@ -6364,6 +6442,13 @@ "report_type" ], "properties": { + "captcha_code": { + "type": "string" + }, + "captcha_id": { + "description": "captcha_id", + "type": "string" + }, "content": { "description": "report content", "type": "string", @@ -6468,6 +6553,12 @@ "content" ], "properties": { + "captcha_code": { + "type": "string" + }, + "captcha_id": { + "type": "string" + }, "content": { "type": "string", "maxLength": 65535, @@ -6484,6 +6575,12 @@ "content" ], "properties": { + "captcha_code": { + "type": "string" + }, + "captcha_id": { + "type": "string" + }, "content": { "type": "string", "maxLength": 65535, @@ -6914,6 +7011,7 @@ "type": "integer" }, "have_password": { + "description": "user have password", "type": "boolean" }, "id": { @@ -7690,6 +7788,13 @@ "title" ], "properties": { + "captcha_code": { + "type": "string" + }, + "captcha_id": { + "description": "captcha_id", + "type": "string" + }, "content": { "description": "content", "type": "string", @@ -7725,6 +7830,13 @@ "maxLength": 65535, "minLength": 6 }, + "captcha_code": { + "type": "string" + }, + "captcha_id": { + "description": "captcha_id", + "type": "string" + }, "content": { "description": "content", "type": "string", @@ -7886,6 +7998,13 @@ "title" ], "properties": { + "captcha_code": { + "type": "string" + }, + "captcha_id": { + "description": "captcha_id", + "type": "string" + }, "content": { "description": "content", "type": "string", @@ -7927,6 +8046,13 @@ "id" ], "properties": { + "captcha_code": { + "type": "string" + }, + "captcha_id": { + "description": "captcha_id", + "type": "string" + }, "id": { "type": "string" }, @@ -7944,8 +8070,13 @@ "id" ], "properties": { + "captcha_code": { + "type": "string" + }, + "captcha_id": { + "type": "string" + }, "id": { - "description": "answer id", "type": "string" } } @@ -7956,6 +8087,13 @@ "comment_id" ], "properties": { + "captcha_code": { + "type": "string" + }, + "captcha_id": { + "description": "captcha_id", + "type": "string" + }, "comment_id": { "description": "comment id", "type": "string" @@ -7968,6 +8106,13 @@ "id" ], "properties": { + "captcha_code": { + "type": "string" + }, + "captcha_id": { + "description": "captcha_id", + "type": "string" + }, "id": { "description": "question id", "type": "string" @@ -8029,24 +8174,6 @@ } } }, - "schema.SearchListResp": { - "type": "object", - "properties": { - "count": { - "type": "integer" - }, - "extra": { - "description": "extra fields" - }, - "list": { - "description": "search response", - "type": "array", - "items": { - "$ref": "#/definitions/schema.SearchResp" - } - } - } - }, "schema.SearchObject": { "type": "object", "properties": { @@ -8096,6 +8223,21 @@ } }, "schema.SearchResp": { + "type": "object", + "properties": { + "count": { + "type": "integer" + }, + "list": { + "description": "search response", + "type": "array", + "items": { + "$ref": "#/definitions/schema.SearchResult" + } + } + } + }, + "schema.SearchResult": { "type": "object", "properties": { "object": { @@ -8717,6 +8859,13 @@ "original_text" ], "properties": { + "captcha_code": { + "type": "string" + }, + "captcha_id": { + "description": "captcha_id", + "type": "string" + }, "comment_id": { "description": "comment id", "type": "string" @@ -8992,39 +9141,30 @@ "type": "object", "properties": { "avatar": { - "description": "avatar", "type": "string" }, "display_name": { - "description": "display_name", "type": "string" }, "id": { - "description": "user_id", "type": "string" }, "ip_info": { - "description": "ip info", "type": "string" }, "location": { - "description": "location", "type": "string" }, "rank": { - "description": "rank", "type": "integer" }, "status": { - "description": "status", "type": "string" }, "username": { - "description": "name", "type": "string" }, "website": { - "description": "website", "type": "string" } } @@ -9066,7 +9206,7 @@ } } }, - "schema.UserEmailLogin": { + "schema.UserEmailLoginReq": { "type": "object", "required": [ "e_mail", @@ -9074,20 +9214,16 @@ ], "properties": { "captcha_code": { - "description": "captcha_code", "type": "string" }, "captcha_id": { - "description": "captcha_id", "type": "string" }, "e_mail": { - "description": "e_mail", "type": "string", "maxLength": 500 }, "pass": { - "description": "password", "type": "string", "maxLength": 32, "minLength": 8 @@ -9297,12 +9433,10 @@ ], "properties": { "code": { - "description": "code", "type": "string", "maxLength": 100 }, "pass": { - "description": "Password", "type": "string", "maxLength": 32 } @@ -9317,25 +9451,20 @@ ], "properties": { "captcha_code": { - "description": "captcha_code", "type": "string" }, "captcha_id": { - "description": "captcha_id", "type": "string" }, "e_mail": { - "description": "email", "type": "string", "maxLength": 500 }, "name": { - "description": "name", "type": "string", "maxLength": 30 }, "pass": { - "description": "password", "type": "string", "maxLength": 32, "minLength": 8 @@ -9349,15 +9478,12 @@ ], "properties": { "captcha_code": { - "description": "captcha_code", "type": "string" }, "captcha_id": { - "description": "captcha_id", "type": "string" }, "e_mail": { - "description": "e_mail", "type": "string", "maxLength": 500 } @@ -9369,6 +9495,13 @@ "object_id" ], "properties": { + "captcha_code": { + "type": "string" + }, + "captcha_id": { + "description": "captcha_id", + "type": "string" + }, "is_cancel": { "description": "is cancel", "type": "boolean" diff --git a/docs/swagger.yaml b/docs/swagger.yaml index 5781165d8..b7408b438 100644 --- a/docs/swagger.yaml +++ b/docs/swagger.yaml @@ -146,6 +146,11 @@ definitions: type: object schema.AddCommentReq: properties: + captcha_code: + type: string + captcha_id: + description: captcha_id + type: string mention_username_list: description: '@ user id list' items: @@ -168,6 +173,11 @@ definitions: type: object schema.AddReportReq: properties: + captcha_code: + type: string + captcha_id: + description: captcha_id + type: string content: description: report content maxLength: 500 @@ -243,6 +253,10 @@ definitions: type: object schema.AnswerAddReq: properties: + captcha_code: + type: string + captcha_id: + type: string content: maxLength: 65535 minLength: 6 @@ -254,6 +268,10 @@ definitions: type: object schema.AnswerUpdateReq: properties: + captcha_code: + type: string + captcha_id: + type: string content: maxLength: 65535 minLength: 6 @@ -559,6 +577,7 @@ definitions: description: follow count type: integer have_password: + description: user have password type: boolean id: description: user id @@ -1104,6 +1123,11 @@ definitions: type: object schema.QuestionAdd: properties: + captcha_code: + type: string + captcha_id: + description: captcha_id + type: string content: description: content maxLength: 65535 @@ -1130,6 +1154,11 @@ definitions: maxLength: 65535 minLength: 6 type: string + captcha_code: + type: string + captcha_id: + description: captcha_id + type: string content: description: content maxLength: 65535 @@ -1244,6 +1273,11 @@ definitions: type: object schema.QuestionUpdate: properties: + captcha_code: + type: string + captcha_id: + description: captcha_id + type: string content: description: content maxLength: 65535 @@ -1277,6 +1311,11 @@ definitions: type: object schema.QuestionUpdateInviteUser: properties: + captcha_code: + type: string + captcha_id: + description: captcha_id + type: string id: type: string invite_user: @@ -1288,14 +1327,22 @@ definitions: type: object schema.RemoveAnswerReq: properties: + captcha_code: + type: string + captcha_id: + type: string id: - description: answer id type: string required: - id type: object schema.RemoveCommentReq: properties: + captcha_code: + type: string + captcha_id: + description: captcha_id + type: string comment_id: description: comment id type: string @@ -1304,6 +1351,11 @@ definitions: type: object schema.RemoveQuestionReq: properties: + captcha_code: + type: string + captcha_id: + description: captcha_id + type: string id: description: question id type: string @@ -1347,18 +1399,6 @@ definitions: - id - operation type: object - schema.SearchListResp: - properties: - count: - type: integer - extra: - description: extra fields - list: - description: search response - items: - $ref: '#/definitions/schema.SearchResp' - type: array - type: object schema.SearchObject: properties: accepted: @@ -1391,6 +1431,16 @@ definitions: type: integer type: object schema.SearchResp: + properties: + count: + type: integer + list: + description: search response + items: + $ref: '#/definitions/schema.SearchResult' + type: array + type: object + schema.SearchResult: properties: object: allOf: @@ -1813,6 +1863,11 @@ definitions: type: object schema.UpdateCommentReq: properties: + captcha_code: + type: string + captcha_id: + description: captcha_id + type: string comment_id: description: comment id type: string @@ -2009,31 +2064,22 @@ definitions: schema.UserBasicInfo: properties: avatar: - description: avatar type: string display_name: - description: display_name type: string id: - description: user_id type: string ip_info: - description: ip info type: string location: - description: location type: string rank: - description: rank type: integer status: - description: status type: string username: - description: name type: string website: - description: website type: string type: object schema.UserChangeEmailSendCodeReq: @@ -2062,20 +2108,16 @@ definitions: required: - code type: object - schema.UserEmailLogin: + schema.UserEmailLoginReq: properties: captcha_code: - description: captcha_code type: string captcha_id: - description: captcha_id type: string e_mail: - description: e_mail maxLength: 500 type: string pass: - description: password maxLength: 32 minLength: 8 type: string @@ -2226,11 +2268,9 @@ definitions: schema.UserRePassWordRequest: properties: code: - description: code maxLength: 100 type: string pass: - description: Password maxLength: 32 type: string required: @@ -2240,21 +2280,16 @@ definitions: schema.UserRegisterReq: properties: captcha_code: - description: captcha_code type: string captcha_id: - description: captcha_id type: string e_mail: - description: email maxLength: 500 type: string name: - description: name maxLength: 30 type: string pass: - description: password maxLength: 32 minLength: 8 type: string @@ -2266,13 +2301,10 @@ definitions: schema.UserRetrievePassWordRequest: properties: captcha_code: - description: captcha_code type: string captcha_id: - description: captcha_id type: string e_mail: - description: e_mail maxLength: 500 type: string required: @@ -2280,6 +2312,11 @@ definitions: type: object schema.VoteReq: properties: + captcha_code: + type: string + captcha_id: + description: captcha_id + type: string is_cancel: description: is cancel type: boolean @@ -3344,6 +3381,30 @@ paths: summary: update user tags: - admin + /answer/admin/api/users: + post: + consumes: + - application/json + description: add users + parameters: + - description: user + in: body + name: data + required: true + schema: + $ref: '#/definitions/schema.AddUserReq' + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/handler.RespBody' + security: + - ApiKeyAuth: [] + summary: add users + tags: + - admin /answer/admin/api/users/activation: post: description: send user activation @@ -5038,13 +5099,31 @@ paths: - $ref: '#/definitions/handler.RespBody' - properties: data: - $ref: '#/definitions/schema.SearchListResp' + $ref: '#/definitions/schema.SearchResp' type: object security: - ApiKeyAuth: [] summary: search object tags: - Search + /answer/api/v1/search/desc: + get: + description: get search description + produces: + - application/json + responses: + "200": + description: OK + schema: + allOf: + - $ref: '#/definitions/handler.RespBody' + - properties: + data: + $ref: '#/definitions/schema.SearchResp' + type: object + summary: get search description + tags: + - Search /answer/api/v1/siteinfo: get: description: get site info @@ -5582,7 +5661,7 @@ paths: name: data required: true schema: - $ref: '#/definitions/schema.UserEmailLogin' + $ref: '#/definitions/schema.UserEmailLoginReq' produces: - application/json responses: diff --git a/internal/service/user_admin/user_backyard.go b/internal/service/user_admin/user_backyard.go index 5db7f966d..fc2689d37 100644 --- a/internal/service/user_admin/user_backyard.go +++ b/internal/service/user_admin/user_backyard.go @@ -190,7 +190,24 @@ func (us *UserAdminService) formatBulkAddUsers(ctx context.Context, req *schema. lang := handler.GetLangByCtx(ctx) val := validator.GetValidatorByLang(lang) errorData := &schema.AddUsersErrorData{Line: -1} + existEmails := make(map[string]bool) + existDisplayNames := make(map[string]bool) for line, user := range req.Users { + if existEmails[user.Email] { + errorData.Field = "email" + errorData.Line = line + 1 + errorData.Content = user.Email + errorData.ExtraMessage = translator.Tr(lang, reason.EmailDuplicate) + break + } + if existDisplayNames[user.DisplayName] { + errorData.Field = "displayName" + errorData.Line = line + 1 + errorData.Content = user.DisplayName + errorData.ExtraMessage = translator.Tr(lang, reason.UsernameDuplicate) + break + } + if fields, e := val.Check(user); e != nil { errorData.SetErrField(fields) errorData.Line = line + 1 @@ -227,6 +244,8 @@ func (us *UserAdminService) formatBulkAddUsers(ctx context.Context, req *schema. userInfo.Status = entity.UserStatusAvailable userInfo.Rank = 1 users = append(users, userInfo) + existEmails[user.Email] = true + existDisplayNames[user.DisplayName] = true } if errorData.Line != -1 {