mirror of
https://github.com/go-gitea/gitea
synced 2025-11-15 18:58:12 +00:00
feat: add pagination support and update swagger documentation
This commit is contained in:
@@ -12,13 +12,14 @@ import (
|
||||
"code.gitea.io/gitea/modules/optional"
|
||||
api "code.gitea.io/gitea/modules/structs"
|
||||
"code.gitea.io/gitea/modules/web"
|
||||
"code.gitea.io/gitea/routers/api/v1/utils"
|
||||
"code.gitea.io/gitea/services/context"
|
||||
"code.gitea.io/gitea/services/convert"
|
||||
)
|
||||
|
||||
// CreateProject creates a new project for organization
|
||||
func CreateProject(ctx *context.APIContext) {
|
||||
// swagger:operation POST /orgs/{org}/projects project createProject
|
||||
// swagger:operation POST /orgs/{org}/projects project orgCreateProject
|
||||
// ---
|
||||
// summary: Create a new project
|
||||
// consumes:
|
||||
@@ -71,7 +72,7 @@ func CreateProject(ctx *context.APIContext) {
|
||||
|
||||
// GetProjects returns a list of projects that belong to an organization
|
||||
func GetProjects(ctx *context.APIContext) {
|
||||
// swagger:operation GET /orgs/{org}/projects project getProjects
|
||||
// swagger:operation GET /orgs/{org}/projects project orgGetProjects
|
||||
// ---
|
||||
// summary: Get a list of projects
|
||||
// produces:
|
||||
@@ -82,6 +83,14 @@ func GetProjects(ctx *context.APIContext) {
|
||||
// description: organization name that the project belongs to
|
||||
// required: true
|
||||
// type: string
|
||||
// - name: page
|
||||
// in: query
|
||||
// description: page number of results to return (1-based)
|
||||
// type: integer
|
||||
// - name: limit
|
||||
// in: query
|
||||
// description: page size of results
|
||||
// type: integer
|
||||
// responses:
|
||||
// "200":
|
||||
// "$ref": "#/responses/ProjectList"
|
||||
@@ -92,23 +101,27 @@ func GetProjects(ctx *context.APIContext) {
|
||||
// "423":
|
||||
// "$ref": "#/responses/repoArchivedError"
|
||||
|
||||
listOptions := utils.GetListOptions(ctx)
|
||||
sortType := ctx.FormTrim("sort")
|
||||
|
||||
isShowClosed := strings.ToLower(ctx.FormTrim("state")) == "closed"
|
||||
|
||||
searchOptions := project_model.SearchOptions{
|
||||
IsClosed: optional.Some(isShowClosed),
|
||||
OrderBy: project_model.GetSearchOrderByBySortType(sortType),
|
||||
OwnerID: ctx.ContextUser.ID,
|
||||
Type: project_model.TypeOrganization,
|
||||
ListOptions: listOptions,
|
||||
IsClosed: optional.Some(isShowClosed),
|
||||
OrderBy: project_model.GetSearchOrderByBySortType(sortType),
|
||||
OwnerID: ctx.ContextUser.ID,
|
||||
Type: project_model.TypeOrganization,
|
||||
}
|
||||
|
||||
projects, err := db.Find[project_model.Project](ctx, &searchOptions)
|
||||
projects, maxResults, err := db.FindAndCount[project_model.Project](ctx, &searchOptions)
|
||||
|
||||
if err != nil {
|
||||
ctx.ServerError("FindProjects", err)
|
||||
ctx.Error(http.StatusInternalServerError, "db.FindAndCount[project_model.Project]", err)
|
||||
return
|
||||
}
|
||||
|
||||
ctx.SetLinkHeader(int(maxResults), listOptions.PageSize)
|
||||
ctx.SetTotalCountHeader(maxResults)
|
||||
ctx.JSON(http.StatusOK, convert.ToProjects(ctx, projects))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user