feat: api endpoints for the boards
This commit is contained in:
@@ -1747,11 +1747,23 @@ func Routes() *web.Route {
|
||||
}, tokenRequiresScopes(auth_model.AccessTokenScopeCategoryAdmin), reqToken(), reqSiteAdmin())
|
||||
|
||||
m.Group("/projects", func() {
|
||||
m.
|
||||
Combo("/{id}").
|
||||
Get(projects.GetProject).
|
||||
Patch(bind(api.UpdateProjectPayload{}), projects.UpdateProject).
|
||||
Delete(projects.DeleteProject)
|
||||
m.Group("/{projectId}", func() {
|
||||
m.Combo("").
|
||||
Get(projects.GetProject).
|
||||
Patch(bind(api.UpdateProjectPayload{}), projects.UpdateProject).
|
||||
Delete(projects.DeleteProject)
|
||||
m.Combo("/boards").
|
||||
Get(projects.ListProjectBoards).
|
||||
Post(bind(api.NewProjectBoardPayload{}), projects.CreateProjectBoard)
|
||||
})
|
||||
|
||||
m.Group("/boards", func() {
|
||||
m.Combo("/{boardId}").
|
||||
Get(projects.GetProjectBoard).
|
||||
Patch(bind(api.UpdateProjectBoardPayload{}), projects.UpdateProjectBoard).
|
||||
Delete(projects.DeleteProjectBoard)
|
||||
})
|
||||
|
||||
}, tokenRequiresScopes(auth_model.AccessTokenScopeCategoryIssue), reqToken())
|
||||
m.Group("/topics", func() {
|
||||
m.Get("/search", repo.TopicSearch)
|
||||
|
||||
242
routers/api/v1/projects/boards.go
Normal file
242
routers/api/v1/projects/boards.go
Normal file
@@ -0,0 +1,242 @@
|
||||
// Copyright 2023 The Gitea Authors. All rights reserved.
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
package projects
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
project_model "code.gitea.io/gitea/models/project"
|
||||
"code.gitea.io/gitea/modules/context"
|
||||
"code.gitea.io/gitea/modules/setting"
|
||||
api "code.gitea.io/gitea/modules/structs"
|
||||
"code.gitea.io/gitea/modules/web"
|
||||
"code.gitea.io/gitea/services/convert"
|
||||
)
|
||||
|
||||
func ListProjectBoards(ctx *context.APIContext) {
|
||||
// swagger:operation GET /projects/{projectId}/boards board boardGetProjectBoards
|
||||
// ---
|
||||
// summary: Get project boards
|
||||
// produces:
|
||||
// - application/json
|
||||
// parameters:
|
||||
// - name: id
|
||||
// in: path
|
||||
// description: id of the project
|
||||
// type: string
|
||||
// required: true
|
||||
// - 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/ProjectBoardList"
|
||||
// "403":
|
||||
// "$ref": "#/responses/forbidden"
|
||||
// "404":
|
||||
// "$ref": "#/responses/notFound"
|
||||
project_id := ctx.ParamsInt64(":projectId")
|
||||
project, err := project_model.GetProjectByID(ctx, project_id)
|
||||
if err != nil {
|
||||
ctx.Error(http.StatusNotFound, "ListProjectBoards", err)
|
||||
return
|
||||
}
|
||||
|
||||
boards, count, err := project.GetBoardsAndCount(ctx)
|
||||
if err != nil {
|
||||
ctx.InternalServerError(err)
|
||||
return
|
||||
}
|
||||
|
||||
ctx.SetLinkHeader(int(count), setting.UI.IssuePagingNum)
|
||||
ctx.SetTotalCountHeader(count)
|
||||
|
||||
apiBoards, err := convert.ToApiProjectBoardList(ctx, boards)
|
||||
if err != nil {
|
||||
ctx.InternalServerError(err)
|
||||
return
|
||||
}
|
||||
|
||||
ctx.JSON(200, apiBoards)
|
||||
|
||||
}
|
||||
|
||||
func CreateProjectBoard(ctx *context.APIContext) {
|
||||
// swagger:operation POST /projects/{projectId}/boards board boardCreateProjectBoard
|
||||
// ---
|
||||
// summary: Create project board
|
||||
// produces:
|
||||
// - application/json
|
||||
// consumes:
|
||||
// - application/json
|
||||
// parameters:
|
||||
// - name: id
|
||||
// in: path
|
||||
// description: id of the project
|
||||
// type: string
|
||||
// required: true
|
||||
// - name: board
|
||||
// in: body
|
||||
// required: true
|
||||
// schema: { "$ref": "#/definitions/NewProjectBoardPayload" }
|
||||
//
|
||||
// responses:
|
||||
//
|
||||
// "201":
|
||||
// "$ref": "#/responses/ProjectBoard"
|
||||
// "403":
|
||||
// "$ref": "#/responses/forbidden"
|
||||
// "404":
|
||||
// "$ref": "#/responses/notFound"
|
||||
form := web.GetForm(ctx).(*api.NewProjectBoardPayload)
|
||||
|
||||
board := &project_model.Board{
|
||||
Title: form.Title,
|
||||
Default: form.Default,
|
||||
Sorting: form.Sorting,
|
||||
Color: form.Color,
|
||||
ProjectID: ctx.ParamsInt64(":projectId"),
|
||||
CreatorID: ctx.Doer.ID,
|
||||
}
|
||||
|
||||
if err := project_model.NewBoard(ctx, board); err != nil {
|
||||
ctx.InternalServerError(err)
|
||||
return
|
||||
}
|
||||
|
||||
board, err := project_model.GetBoard(ctx, board.ID)
|
||||
if err != nil {
|
||||
ctx.InternalServerError(err)
|
||||
return
|
||||
}
|
||||
|
||||
ctx.JSON(http.StatusCreated, convert.ToAPIProjectBoard(ctx, board))
|
||||
}
|
||||
|
||||
func GetProjectBoard(ctx *context.APIContext) {
|
||||
// swagger:operation GET /projects/boards/{boardId} board boardGetProjectBoard
|
||||
// ---
|
||||
// summary: Get project board
|
||||
// produces:
|
||||
// - application/json
|
||||
// parameters:
|
||||
// - name: id
|
||||
// in: path
|
||||
// description: id of the board
|
||||
// type: string
|
||||
// required: true
|
||||
//
|
||||
// responses:
|
||||
//
|
||||
// "200":
|
||||
// "$ref": "#/responses/ProjectBoard"
|
||||
// "403":
|
||||
// "$ref": "#/responses/forbidden"
|
||||
// "404":
|
||||
// "$ref": "#/responses/notFound"
|
||||
board, err := project_model.GetBoard(ctx, ctx.ParamsInt64(":boardId"))
|
||||
if err != nil {
|
||||
if project_model.IsErrProjectBoardNotExist(err) {
|
||||
ctx.Error(http.StatusNotFound, "GetProjectBoard", err)
|
||||
} else {
|
||||
ctx.Error(http.StatusInternalServerError, "GetProjectBoard", err)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
ctx.JSON(http.StatusOK, convert.ToAPIProjectBoard(ctx, board))
|
||||
}
|
||||
|
||||
func UpdateProjectBoard(ctx *context.APIContext) {
|
||||
// swagger:operation PATCH /projects/boards/{boardId} board boardUpdateProjectBoard
|
||||
// ---
|
||||
// summary: Update project board
|
||||
// produces:
|
||||
// - application/json
|
||||
// consumes:
|
||||
// - application/json
|
||||
// parameters:
|
||||
// - name: id
|
||||
// in: path
|
||||
// description: id of the project board
|
||||
// type: string
|
||||
// required: true
|
||||
// - name: board
|
||||
// in: body
|
||||
// required: true
|
||||
// schema: { "$ref": "#/definitions/UpdateProjectBoardPayload" }
|
||||
//
|
||||
// responses:
|
||||
//
|
||||
// "200":
|
||||
// "$ref": "#/responses/ProjectBoard"
|
||||
// "403":
|
||||
// "$ref": "#/responses/forbidden"
|
||||
// "404":
|
||||
// "$ref": "#/responses/notFound"
|
||||
|
||||
form := web.GetForm(ctx).(*api.UpdateProjectBoardPayload)
|
||||
|
||||
board, err := project_model.GetBoard(ctx, ctx.ParamsInt64(":boardId"))
|
||||
if err != nil {
|
||||
ctx.InternalServerError(err)
|
||||
return
|
||||
}
|
||||
|
||||
if board.Title != form.Title {
|
||||
board.Title = form.Title
|
||||
}
|
||||
if board.Color != form.Color {
|
||||
board.Color = form.Color
|
||||
}
|
||||
|
||||
if err := project_model.UpdateBoard(ctx, board); err != nil {
|
||||
ctx.InternalServerError(err)
|
||||
return
|
||||
}
|
||||
|
||||
board, err = project_model.GetBoard(ctx, board.ID)
|
||||
if err != nil {
|
||||
ctx.InternalServerError(err)
|
||||
return
|
||||
}
|
||||
|
||||
ctx.JSON(200, convert.ToAPIProjectBoard(ctx, board))
|
||||
}
|
||||
|
||||
func DeleteProjectBoard(ctx *context.APIContext) {
|
||||
// swagger:operation DELETE /projects/boards/{boardId} board boardDeleteProjectBoard
|
||||
// ---
|
||||
// summary: Delete project board
|
||||
// produces:
|
||||
// - application/json
|
||||
// parameters:
|
||||
// - name: id
|
||||
// in: path
|
||||
// description: id of the project board
|
||||
// type: string
|
||||
// required: true
|
||||
//
|
||||
// responses:
|
||||
//
|
||||
// "204":
|
||||
// "description": "Project board deleted"
|
||||
// "403":
|
||||
// "$ref": "#/responses/forbidden"
|
||||
// "404":
|
||||
// "$ref": "#/responses/notFound"
|
||||
if err := project_model.DeleteBoardByID(ctx, ctx.ParamsInt64(":boardId")); err != nil {
|
||||
ctx.InternalServerError(err)
|
||||
return
|
||||
}
|
||||
|
||||
ctx.Status(http.StatusNoContent)
|
||||
}
|
||||
@@ -136,7 +136,7 @@ func CreateRepoProject(ctx *context.APIContext) {
|
||||
}
|
||||
|
||||
func GetProject(ctx *context.APIContext) {
|
||||
// swagger:operation GET /projects/{id} project projectGetProject
|
||||
// swagger:operation GET /projects/{projectId} project projectGetProject
|
||||
// ---
|
||||
// summary: Get project
|
||||
// produces:
|
||||
@@ -154,7 +154,7 @@ func GetProject(ctx *context.APIContext) {
|
||||
// "$ref": "#/responses/forbidden"
|
||||
// "404":
|
||||
// "$ref": "#/responses/notFound"
|
||||
project, err := project_model.GetProjectByID(ctx, ctx.ParamsInt64(":id"))
|
||||
project, err := project_model.GetProjectByID(ctx, ctx.ParamsInt64(":projectId"))
|
||||
if err != nil {
|
||||
if project_model.IsErrProjectNotExist(err) {
|
||||
ctx.NotFound()
|
||||
@@ -168,7 +168,7 @@ func GetProject(ctx *context.APIContext) {
|
||||
}
|
||||
|
||||
func UpdateProject(ctx *context.APIContext) {
|
||||
// swagger:operation PATCH /projects/{id} project projectUpdateProject
|
||||
// swagger:operation PATCH /projects/{projectId} project projectUpdateProject
|
||||
// ---
|
||||
// summary: Update project
|
||||
// produces:
|
||||
@@ -193,7 +193,7 @@ func UpdateProject(ctx *context.APIContext) {
|
||||
// "404":
|
||||
// "$ref": "#/responses/notFound"
|
||||
form := web.GetForm(ctx).(*api.UpdateProjectPayload)
|
||||
project, err := project_model.GetProjectByID(ctx, ctx.ParamsInt64("id"))
|
||||
project, err := project_model.GetProjectByID(ctx, ctx.ParamsInt64(":projectId"))
|
||||
if err != nil {
|
||||
if project_model.IsErrProjectNotExist(err) {
|
||||
ctx.NotFound()
|
||||
@@ -218,7 +218,7 @@ func UpdateProject(ctx *context.APIContext) {
|
||||
}
|
||||
|
||||
func DeleteProject(ctx *context.APIContext) {
|
||||
// swagger:operation DELETE /projects/{id} project projectDeleteProject
|
||||
// swagger:operation DELETE /projects/{projectId} project projectDeleteProject
|
||||
// ---
|
||||
// summary: Delete project
|
||||
// parameters:
|
||||
@@ -235,7 +235,7 @@ func DeleteProject(ctx *context.APIContext) {
|
||||
// "404":
|
||||
// "$ref": "#/responses/notFound"
|
||||
|
||||
if err := project_model.DeleteProjectByID(ctx, ctx.ParamsInt64(":id")); err != nil {
|
||||
if err := project_model.DeleteProjectByID(ctx, ctx.ParamsInt64(":projectId")); err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "DeleteProjectByID", err)
|
||||
return
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user