|
| 1 | +// Copyright 2023 The Gitea Authors. All rights reserved. |
| 2 | +// SPDX-License-Identifier: MIT |
| 3 | + |
| 4 | +package admin |
| 5 | + |
| 6 | +import ( |
| 7 | + "net/http" |
| 8 | + |
| 9 | + user_model "code.gitea.io/gitea/models/user" |
| 10 | + "code.gitea.io/gitea/modules/context" |
| 11 | + api "code.gitea.io/gitea/modules/structs" |
| 12 | + "code.gitea.io/gitea/routers/api/v1/utils" |
| 13 | + "code.gitea.io/gitea/services/convert" |
| 14 | +) |
| 15 | + |
| 16 | +// GetAllEmails |
| 17 | +func GetAllEmails(ctx *context.APIContext) { |
| 18 | + // swagger:operation GET /admin/emails admin adminGetAllEmails |
| 19 | + // --- |
| 20 | + // summary: List all emails |
| 21 | + // produces: |
| 22 | + // - application/json |
| 23 | + // parameters: |
| 24 | + // - name: page |
| 25 | + // in: query |
| 26 | + // description: page number of results to return (1-based) |
| 27 | + // type: integer |
| 28 | + // - name: limit |
| 29 | + // in: query |
| 30 | + // description: page size of results |
| 31 | + // type: integer |
| 32 | + // responses: |
| 33 | + // "200": |
| 34 | + // "$ref": "#/responses/EmailList" |
| 35 | + // "403": |
| 36 | + // "$ref": "#/responses/forbidden" |
| 37 | + |
| 38 | + listOptions := utils.GetListOptions(ctx) |
| 39 | + |
| 40 | + emails, maxResults, err := user_model.SearchEmails(&user_model.SearchEmailOptions{ |
| 41 | + Keyword: ctx.Params(":email"), |
| 42 | + ListOptions: listOptions, |
| 43 | + }) |
| 44 | + if err != nil { |
| 45 | + ctx.Error(http.StatusInternalServerError, "GetAllEmails", err) |
| 46 | + return |
| 47 | + } |
| 48 | + |
| 49 | + results := make([]*api.Email, len(emails)) |
| 50 | + for i := range emails { |
| 51 | + results[i] = convert.ToEmailSearch(emails[i]) |
| 52 | + } |
| 53 | + |
| 54 | + ctx.SetLinkHeader(int(maxResults), listOptions.PageSize) |
| 55 | + ctx.SetTotalCountHeader(maxResults) |
| 56 | + ctx.JSON(http.StatusOK, &results) |
| 57 | +} |
| 58 | + |
| 59 | +// SearchEmail |
| 60 | +func SearchEmail(ctx *context.APIContext) { |
| 61 | + // swagger:operation GET /admin/emails/search admin adminSearchEmails |
| 62 | + // --- |
| 63 | + // summary: Search all emails |
| 64 | + // produces: |
| 65 | + // - application/json |
| 66 | + // parameters: |
| 67 | + // - name: q |
| 68 | + // in: query |
| 69 | + // description: keyword |
| 70 | + // type: string |
| 71 | + // - name: page |
| 72 | + // in: query |
| 73 | + // description: page number of results to return (1-based) |
| 74 | + // type: integer |
| 75 | + // - name: limit |
| 76 | + // in: query |
| 77 | + // description: page size of results |
| 78 | + // type: integer |
| 79 | + // responses: |
| 80 | + // "200": |
| 81 | + // "$ref": "#/responses/EmailList" |
| 82 | + // "403": |
| 83 | + // "$ref": "#/responses/forbidden" |
| 84 | + |
| 85 | + ctx.SetParams(":email", ctx.FormTrim("q")) |
| 86 | + GetAllEmails(ctx) |
| 87 | +} |
0 commit comments