@@ -17,13 +17,14 @@ import (
1717 api "code.gitea.io/gitea/modules/structs"
1818 "code.gitea.io/gitea/modules/util"
1919 "code.gitea.io/gitea/modules/web"
20+ "code.gitea.io/gitea/routers/api/v1/utils"
2021 "code.gitea.io/gitea/services/context"
2122 "code.gitea.io/gitea/services/convert"
2223)
2324
2425// GetProjects returns a list of projects for a given user and repository.
2526func GetProjects (ctx * context.APIContext ) {
26- // swagger:operation GET /repos/{owner}/{reponame}/projects project getProjects
27+ // swagger:operation GET /repos/{owner}/{reponame}/projects project repoGetProjects
2728 // ---
2829 // summary: Get a list of projects
2930 // description: Returns a list of projects for a given user and repository.
@@ -40,6 +41,14 @@ func GetProjects(ctx *context.APIContext) {
4041 // description: repository name.
4142 // required: true
4243 // type: string
44+ // - name: page
45+ // in: query
46+ // description: page number of results to return (1-based)
47+ // type: integer
48+ // - name: limit
49+ // in: query
50+ // description: page size of results
51+ // type: integer
4352 // responses:
4453 // "200":
4554 // "$ref": "#/responses/ProjectList"
@@ -50,30 +59,34 @@ func GetProjects(ctx *context.APIContext) {
5059 // "423":
5160 // "$ref": "#/responses/repoArchivedError"
5261
62+ listOptions := utils .GetListOptions (ctx )
5363 sortType := ctx .FormTrim ("sort" )
5464
5565 isShowClosed := strings .ToLower (ctx .FormTrim ("state" )) == "closed"
5666
5767 searchOptions := project_model.SearchOptions {
58- IsClosed : optional .Some (isShowClosed ),
59- OrderBy : project_model .GetSearchOrderByBySortType (sortType ),
60- RepoID : ctx .Repo .Repository .ID ,
61- Type : project_model .TypeRepository ,
68+ ListOptions : listOptions ,
69+ IsClosed : optional .Some (isShowClosed ),
70+ OrderBy : project_model .GetSearchOrderByBySortType (sortType ),
71+ RepoID : ctx .Repo .Repository .ID ,
72+ Type : project_model .TypeRepository ,
6273 }
6374
64- projects , err := db .Find [project_model.Project ](ctx , & searchOptions )
75+ projects , maxResults , err := db .FindAndCount [project_model.Project ](ctx , & searchOptions )
6576
6677 if err != nil {
67- ctx .ServerError ( "FindProjects " , err )
78+ ctx .Error ( http . StatusInternalServerError , "db.FindAndCount[project_model.Project] " , err )
6879 return
6980 }
7081
82+ ctx .SetLinkHeader (int (maxResults ), listOptions .PageSize )
83+ ctx .SetTotalCountHeader (maxResults )
7184 ctx .JSON (http .StatusOK , convert .ToProjects (ctx , projects ))
7285}
7386
7487// CreateProject creates a new project
7588func CreateProject (ctx * context.APIContext ) {
76- // swagger:operation POST /repos/{owner}/{reponame}/projects project createProject
89+ // swagger:operation POST /repos/{owner}/{reponame}/projects project repoCreateProject
7790 // ---
7891 // summary: Create a new project
7992 // description: Creates a new project for a given user and repository.
@@ -132,7 +145,7 @@ func CreateProject(ctx *context.APIContext) {
132145
133146// UpdateIssueProject change an issue's project to another project in a repository
134147func UpdateIssueProject (ctx * context.APIContext ) {
135- // swagger:operation PUT /repos/{owner}/{reponame}/projects/{type} project updateIssueProject
148+ // swagger:operation PUT /repos/{owner}/{reponame}/projects/{type} project repoUpdateIssueProject
136149 // ---
137150 // summary: Change an issue's project
138151 // consumes:
0 commit comments