1
1
mirror of https://github.com/go-gitea/gitea synced 2025-07-22 18:28:37 +00:00

api: create endpoint for changing project status

This commit is contained in:
eyad-hussein
2024-07-10 10:32:46 +03:00
parent 5814b6d590
commit 773bd91232
2 changed files with 53 additions and 1 deletions

View File

@@ -10,6 +10,7 @@ import (
"code.gitea.io/gitea/services/context"
)
// CreateProject creates a new project
func CreateProject(ctx *context.APIContext) {
form := web.GetForm(ctx).(*api.CreateProjectOption)
@@ -37,3 +38,24 @@ func CreateProject(ctx *context.APIContext) {
ctx.JSON(http.StatusCreated, map[string]int64{"id": project.ID})
}
// ChangeProjectStatus updates the status of a project between "open" and "close"
func ChangeProjectStatus(ctx *context.APIContext) {
var toClose bool
switch ctx.PathParam(":action") {
case "open":
toClose = false
case "close":
toClose = true
default:
ctx.NotFound("ChangeProjectStatus", nil)
return
}
id := ctx.PathParamInt64(":id")
if err := project_model.ChangeProjectStatusByRepoIDAndID(ctx, 0, id, toClose); err != nil {
ctx.NotFoundOrServerError("ChangeProjectStatusByRepoIDAndID", project_model.IsErrProjectNotExist, err)
return
}
ctx.JSON(http.StatusOK, map[string]any{"message": "project status updated successfully"})
}