improvements

This commit is contained in:
Lunny Xiao 2025-07-06 13:06:05 -07:00
parent 1faa7e82e3
commit 899efca7c4
No known key found for this signature in database
GPG Key ID: C3B7C91B632F738A
2 changed files with 28 additions and 21 deletions

View File

@ -8,9 +8,9 @@ import (
"code.gitea.io/gitea/models/db"
project_model "code.gitea.io/gitea/models/project"
"code.gitea.io/gitea/modules/setting"
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"
)
@ -283,18 +283,20 @@ func ListUserProjects(ctx *context.APIContext) {
// "$ref": "#/responses/forbidden"
// "404":
// "$ref": "#/responses/notFound"
listOptions := utils.GetListOptions(ctx)
projects, count, err := db.FindAndCount[project_model.Project](ctx, project_model.SearchOptions{
Type: project_model.TypeIndividual,
IsClosed: ctx.FormOptionalBool("closed"),
OwnerID: ctx.Doer.ID,
ListOptions: db.ListOptions{Page: ctx.FormInt("page")},
ListOptions: listOptions,
})
if err != nil {
ctx.APIErrorInternal(err)
return
}
ctx.SetLinkHeader(int(count), setting.UI.IssuePagingNum)
ctx.SetLinkHeader(int(count), listOptions.PageSize)
ctx.SetTotalCountHeader(count)
apiProjects, err := convert.ToAPIProjectList(ctx, projects)
@ -337,9 +339,11 @@ func ListOrgProjects(ctx *context.APIContext) {
// "$ref": "#/responses/forbidden"
// "404":
// "$ref": "#/responses/notFound"
listOptions := utils.GetListOptions(ctx)
projects, count, err := db.FindAndCount[project_model.Project](ctx, project_model.SearchOptions{
OwnerID: ctx.Org.Organization.AsUser().ID,
ListOptions: db.ListOptions{Page: ctx.FormInt("page")},
ListOptions: listOptions,
IsClosed: ctx.FormOptionalBool("closed"),
Type: project_model.TypeOrganization,
})
@ -348,7 +352,7 @@ func ListOrgProjects(ctx *context.APIContext) {
return
}
ctx.SetLinkHeader(int(count), setting.UI.IssuePagingNum)
ctx.SetLinkHeader(int(count), listOptions.PageSize)
ctx.SetTotalCountHeader(count)
apiProjects, err := convert.ToAPIProjectList(ctx, projects)
@ -397,19 +401,19 @@ func ListRepoProjects(ctx *context.APIContext) {
// "404":
// "$ref": "#/responses/notFound"
page := ctx.FormInt("page")
listOptions := utils.GetListOptions(ctx)
projects, count, err := db.FindAndCount[project_model.Project](ctx, project_model.SearchOptions{
RepoID: ctx.Repo.Repository.ID,
IsClosed: ctx.FormOptionalBool("closed"),
Type: project_model.TypeRepository,
ListOptions: db.ListOptions{Page: page},
ListOptions: listOptions,
})
if err != nil {
ctx.APIErrorInternal(err)
return
}
ctx.SetLinkHeader(int(count), page)
ctx.SetLinkHeader(int(count), listOptions.PageSize)
ctx.SetTotalCountHeader(count)
apiProjects, err := convert.ToAPIProjectList(ctx, projects)

View File

@ -3385,7 +3385,7 @@
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/NewProjectPayload"
"$ref": "#/definitions/NewProjectOption"
}
}
],
@ -4308,7 +4308,7 @@
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/UpdateProjectPayload"
"$ref": "#/definitions/UpdateProjectOption"
}
}
],
@ -13687,7 +13687,7 @@
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/NewProjectPayload"
"$ref": "#/definitions/NewProjectOption"
}
}
],
@ -20014,7 +20014,7 @@
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/NewProjectPayload"
"$ref": "#/definitions/NewProjectOption"
}
}
],
@ -26380,7 +26380,8 @@
},
"x-go-package": "code.gitea.io/gitea/modules/structs"
},
"NewProjectPayload": {
"NewProjectOption": {
"description": "NewProjectOption options when creating a new project",
"type": "object",
"required": [
"name",
@ -26391,7 +26392,7 @@
"body": {
"description": "Keep compatibility with Github API to use \"body\" instead of \"description\"",
"type": "string",
"x-go-name": "Description"
"x-go-name": "Body"
},
"card_type": {
"type": "string",
@ -26403,7 +26404,7 @@
},
"name": {
"type": "string",
"x-go-name": "Title"
"x-go-name": "Name"
},
"template_type": {
"type": "string",
@ -26990,6 +26991,7 @@
"x-go-package": "code.gitea.io/gitea/modules/structs"
},
"Project": {
"description": "Project represents a project",
"type": "object",
"required": [
"template_type"
@ -26998,7 +27000,7 @@
"body": {
"description": "Keep compatibility with Github API to use \"body\" instead of \"description\"",
"type": "string",
"x-go-name": "Description"
"x-go-name": "Body"
},
"closed_at": {
"type": "string",
@ -27021,7 +27023,7 @@
"name": {
"description": "Keep compatibility with Github API to use \"name\" instead of \"title\"",
"type": "string",
"x-go-name": "Title"
"x-go-name": "Name"
},
"owner": {
"$ref": "#/definitions/User"
@ -28608,7 +28610,8 @@
},
"x-go-package": "code.gitea.io/gitea/modules/structs"
},
"UpdateProjectPayload": {
"UpdateProjectOption": {
"description": "UpdateProjectOption options when updating a project",
"type": "object",
"required": [
"name"
@ -28617,11 +28620,11 @@
"body": {
"description": "Keep compatibility with Github API to use \"body\" instead of \"description\"",
"type": "string",
"x-go-name": "Description"
"x-go-name": "Body"
},
"name": {
"type": "string",
"x-go-name": "Title"
"x-go-name": "Name"
}
},
"x-go-package": "code.gitea.io/gitea/modules/structs"
@ -30172,7 +30175,7 @@
"parameterBodies": {
"description": "parameterBodies",
"schema": {
"$ref": "#/definitions/UpdateProjectPayload"
"$ref": "#/definitions/UpdateProjectOption"
}
},
"redirect": {