You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

168 lines
4.2 KiB

API add/generalize pagination (#9452) * paginate results * fixed deadlock * prevented breaking change * updated swagger * go fmt * fixed find topic * go mod tidy * go mod vendor with go1.13.5 * fixed repo find topics * fixed unit test * added Limit method to Engine struct; use engine variable when provided; fixed gitignore * use ItemsPerPage for default pagesize; fix GetWatchers, getOrgUsersByOrgID and GetStargazers; fix GetAllCommits headers; reverted some changed behaviors * set Page value on Home route * improved memory allocations * fixed response headers * removed logfiles * fixed import order * import order * improved swagger * added function to get models.ListOptions from context * removed pagesize diff on unit test * fixed imports * removed unnecessary struct field * fixed go fmt * scoped PR * code improvements * code improvements * go mod tidy * fixed import order * fixed commit statuses session * fixed files headers * fixed headers; added pagination for notifications * go mod tidy * go fmt * removed Private from user search options; added setting.UI.IssuePagingNum as default valeu on repo's issues list * Apply suggestions from code review Co-Authored-By: 6543 <6543@obermui.de> Co-Authored-By: zeripath <art27@cantab.net> * fixed build error * CI.restart() * fixed merge conflicts resolve * fixed conflicts resolve * improved FindTrackedTimesOptions.ToOptions() method * added backwards compatibility on ListReleases request; fixed issue tracked time ToSession * fixed build error; fixed swagger template * fixed swagger template * fixed ListReleases backwards compatibility * added page to user search route Co-authored-by: techknowlogick <matti@mdranta.net> Co-authored-by: 6543 <6543@obermui.de> Co-authored-by: zeripath <art27@cantab.net>
4 years ago
API add/generalize pagination (#9452) * paginate results * fixed deadlock * prevented breaking change * updated swagger * go fmt * fixed find topic * go mod tidy * go mod vendor with go1.13.5 * fixed repo find topics * fixed unit test * added Limit method to Engine struct; use engine variable when provided; fixed gitignore * use ItemsPerPage for default pagesize; fix GetWatchers, getOrgUsersByOrgID and GetStargazers; fix GetAllCommits headers; reverted some changed behaviors * set Page value on Home route * improved memory allocations * fixed response headers * removed logfiles * fixed import order * import order * improved swagger * added function to get models.ListOptions from context * removed pagesize diff on unit test * fixed imports * removed unnecessary struct field * fixed go fmt * scoped PR * code improvements * code improvements * go mod tidy * fixed import order * fixed commit statuses session * fixed files headers * fixed headers; added pagination for notifications * go mod tidy * go fmt * removed Private from user search options; added setting.UI.IssuePagingNum as default valeu on repo's issues list * Apply suggestions from code review Co-Authored-By: 6543 <6543@obermui.de> Co-Authored-By: zeripath <art27@cantab.net> * fixed build error * CI.restart() * fixed merge conflicts resolve * fixed conflicts resolve * improved FindTrackedTimesOptions.ToOptions() method * added backwards compatibility on ListReleases request; fixed issue tracked time ToSession * fixed build error; fixed swagger template * fixed swagger template * fixed ListReleases backwards compatibility * added page to user search route Co-authored-by: techknowlogick <matti@mdranta.net> Co-authored-by: 6543 <6543@obermui.de> Co-authored-by: zeripath <art27@cantab.net>
4 years ago
7 years ago
API add/generalize pagination (#9452) * paginate results * fixed deadlock * prevented breaking change * updated swagger * go fmt * fixed find topic * go mod tidy * go mod vendor with go1.13.5 * fixed repo find topics * fixed unit test * added Limit method to Engine struct; use engine variable when provided; fixed gitignore * use ItemsPerPage for default pagesize; fix GetWatchers, getOrgUsersByOrgID and GetStargazers; fix GetAllCommits headers; reverted some changed behaviors * set Page value on Home route * improved memory allocations * fixed response headers * removed logfiles * fixed import order * import order * improved swagger * added function to get models.ListOptions from context * removed pagesize diff on unit test * fixed imports * removed unnecessary struct field * fixed go fmt * scoped PR * code improvements * code improvements * go mod tidy * fixed import order * fixed commit statuses session * fixed files headers * fixed headers; added pagination for notifications * go mod tidy * go fmt * removed Private from user search options; added setting.UI.IssuePagingNum as default valeu on repo's issues list * Apply suggestions from code review Co-Authored-By: 6543 <6543@obermui.de> Co-Authored-By: zeripath <art27@cantab.net> * fixed build error * CI.restart() * fixed merge conflicts resolve * fixed conflicts resolve * improved FindTrackedTimesOptions.ToOptions() method * added backwards compatibility on ListReleases request; fixed issue tracked time ToSession * fixed build error; fixed swagger template * fixed swagger template * fixed ListReleases backwards compatibility * added page to user search route Co-authored-by: techknowlogick <matti@mdranta.net> Co-authored-by: 6543 <6543@obermui.de> Co-authored-by: zeripath <art27@cantab.net>
4 years ago
API add/generalize pagination (#9452) * paginate results * fixed deadlock * prevented breaking change * updated swagger * go fmt * fixed find topic * go mod tidy * go mod vendor with go1.13.5 * fixed repo find topics * fixed unit test * added Limit method to Engine struct; use engine variable when provided; fixed gitignore * use ItemsPerPage for default pagesize; fix GetWatchers, getOrgUsersByOrgID and GetStargazers; fix GetAllCommits headers; reverted some changed behaviors * set Page value on Home route * improved memory allocations * fixed response headers * removed logfiles * fixed import order * import order * improved swagger * added function to get models.ListOptions from context * removed pagesize diff on unit test * fixed imports * removed unnecessary struct field * fixed go fmt * scoped PR * code improvements * code improvements * go mod tidy * fixed import order * fixed commit statuses session * fixed files headers * fixed headers; added pagination for notifications * go mod tidy * go fmt * removed Private from user search options; added setting.UI.IssuePagingNum as default valeu on repo's issues list * Apply suggestions from code review Co-Authored-By: 6543 <6543@obermui.de> Co-Authored-By: zeripath <art27@cantab.net> * fixed build error * CI.restart() * fixed merge conflicts resolve * fixed conflicts resolve * improved FindTrackedTimesOptions.ToOptions() method * added backwards compatibility on ListReleases request; fixed issue tracked time ToSession * fixed build error; fixed swagger template * fixed swagger template * fixed ListReleases backwards compatibility * added page to user search route Co-authored-by: techknowlogick <matti@mdranta.net> Co-authored-by: 6543 <6543@obermui.de> Co-authored-by: zeripath <art27@cantab.net>
4 years ago
API add/generalize pagination (#9452) * paginate results * fixed deadlock * prevented breaking change * updated swagger * go fmt * fixed find topic * go mod tidy * go mod vendor with go1.13.5 * fixed repo find topics * fixed unit test * added Limit method to Engine struct; use engine variable when provided; fixed gitignore * use ItemsPerPage for default pagesize; fix GetWatchers, getOrgUsersByOrgID and GetStargazers; fix GetAllCommits headers; reverted some changed behaviors * set Page value on Home route * improved memory allocations * fixed response headers * removed logfiles * fixed import order * import order * improved swagger * added function to get models.ListOptions from context * removed pagesize diff on unit test * fixed imports * removed unnecessary struct field * fixed go fmt * scoped PR * code improvements * code improvements * go mod tidy * fixed import order * fixed commit statuses session * fixed files headers * fixed headers; added pagination for notifications * go mod tidy * go fmt * removed Private from user search options; added setting.UI.IssuePagingNum as default valeu on repo's issues list * Apply suggestions from code review Co-Authored-By: 6543 <6543@obermui.de> Co-Authored-By: zeripath <art27@cantab.net> * fixed build error * CI.restart() * fixed merge conflicts resolve * fixed conflicts resolve * improved FindTrackedTimesOptions.ToOptions() method * added backwards compatibility on ListReleases request; fixed issue tracked time ToSession * fixed build error; fixed swagger template * fixed swagger template * fixed ListReleases backwards compatibility * added page to user search route Co-authored-by: techknowlogick <matti@mdranta.net> Co-authored-by: 6543 <6543@obermui.de> Co-authored-by: zeripath <art27@cantab.net>
4 years ago
10 years ago
10 years ago
10 years ago
10 years ago
8 years ago
8 years ago
10 years ago
  1. // Copyright 2014 The Gogs Authors. All rights reserved.
  2. // Copyright 2020 The Gitea Authors.
  3. // Use of this source code is governed by a MIT-style
  4. // license that can be found in the LICENSE file.
  5. package user
  6. import (
  7. "net/http"
  8. "strings"
  9. "code.gitea.io/gitea/models"
  10. "code.gitea.io/gitea/modules/context"
  11. "code.gitea.io/gitea/modules/convert"
  12. api "code.gitea.io/gitea/modules/structs"
  13. "code.gitea.io/gitea/routers/api/v1/utils"
  14. "github.com/unknwon/com"
  15. )
  16. // Search search users
  17. func Search(ctx *context.APIContext) {
  18. // swagger:operation GET /users/search user userSearch
  19. // ---
  20. // summary: Search for users
  21. // produces:
  22. // - application/json
  23. // parameters:
  24. // - name: q
  25. // in: query
  26. // description: keyword
  27. // type: string
  28. // - name: uid
  29. // in: query
  30. // description: ID of the user to search for
  31. // type: integer
  32. // format: int64
  33. // - name: page
  34. // in: query
  35. // description: page number of results to return (1-based)
  36. // type: integer
  37. // - name: limit
  38. // in: query
  39. // description: page size of results, maximum page size is 50
  40. // type: integer
  41. // responses:
  42. // "200":
  43. // description: "SearchResults of a successful search"
  44. // schema:
  45. // type: object
  46. // properties:
  47. // ok:
  48. // type: boolean
  49. // data:
  50. // type: array
  51. // items:
  52. // "$ref": "#/definitions/User"
  53. opts := &models.SearchUserOptions{
  54. Keyword: strings.Trim(ctx.Query("q"), " "),
  55. UID: com.StrTo(ctx.Query("uid")).MustInt64(),
  56. Type: models.UserTypeIndividual,
  57. ListOptions: utils.GetListOptions(ctx),
  58. }
  59. users, _, err := models.SearchUsers(opts)
  60. if err != nil {
  61. ctx.JSON(http.StatusInternalServerError, map[string]interface{}{
  62. "ok": false,
  63. "error": err.Error(),
  64. })
  65. return
  66. }
  67. results := make([]*api.User, len(users))
  68. for i := range users {
  69. results[i] = convert.ToUser(users[i], ctx.IsSigned, ctx.User != nil && ctx.User.IsAdmin)
  70. }
  71. ctx.JSON(http.StatusOK, map[string]interface{}{
  72. "ok": true,
  73. "data": results,
  74. })
  75. }
  76. // GetInfo get user's information
  77. func GetInfo(ctx *context.APIContext) {
  78. // swagger:operation GET /users/{username} user userGet
  79. // ---
  80. // summary: Get a user
  81. // produces:
  82. // - application/json
  83. // parameters:
  84. // - name: username
  85. // in: path
  86. // description: username of user to get
  87. // type: string
  88. // required: true
  89. // responses:
  90. // "200":
  91. // "$ref": "#/responses/User"
  92. // "404":
  93. // "$ref": "#/responses/notFound"
  94. u, err := models.GetUserByName(ctx.Params(":username"))
  95. if err != nil {
  96. if models.IsErrUserNotExist(err) {
  97. ctx.NotFound()
  98. } else {
  99. ctx.Error(http.StatusInternalServerError, "GetUserByName", err)
  100. }
  101. return
  102. }
  103. ctx.JSON(http.StatusOK, convert.ToUser(u, ctx.IsSigned, ctx.User != nil && (ctx.User.ID == u.ID || ctx.User.IsAdmin)))
  104. }
  105. // GetAuthenticatedUser get current user's information
  106. func GetAuthenticatedUser(ctx *context.APIContext) {
  107. // swagger:operation GET /user user userGetCurrent
  108. // ---
  109. // summary: Get the authenticated user
  110. // produces:
  111. // - application/json
  112. // responses:
  113. // "200":
  114. // "$ref": "#/responses/User"
  115. ctx.JSON(http.StatusOK, convert.ToUser(ctx.User, ctx.IsSigned, ctx.User != nil))
  116. }
  117. // GetUserHeatmapData is the handler to get a users heatmap
  118. func GetUserHeatmapData(ctx *context.APIContext) {
  119. // swagger:operation GET /users/{username}/heatmap user userGetHeatmapData
  120. // ---
  121. // summary: Get a user's heatmap
  122. // produces:
  123. // - application/json
  124. // parameters:
  125. // - name: username
  126. // in: path
  127. // description: username of user to get
  128. // type: string
  129. // required: true
  130. // responses:
  131. // "200":
  132. // "$ref": "#/responses/UserHeatmapData"
  133. // "404":
  134. // "$ref": "#/responses/notFound"
  135. // Get the user to throw an error if it does not exist
  136. user, err := models.GetUserByName(ctx.Params(":username"))
  137. if err != nil {
  138. if models.IsErrUserNotExist(err) {
  139. ctx.Status(http.StatusNotFound)
  140. } else {
  141. ctx.Error(http.StatusInternalServerError, "GetUserByName", err)
  142. }
  143. return
  144. }
  145. heatmap, err := models.GetUserHeatmapDataByUser(user)
  146. if err != nil {
  147. ctx.Error(http.StatusInternalServerError, "GetUserHeatmapDataByUser", err)
  148. return
  149. }
  150. ctx.JSON(http.StatusOK, heatmap)
  151. }