-
Notifications
You must be signed in to change notification settings - Fork 14.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(core): Support create, read, update, delete projects in Public A…
…PI (#10269)
- Loading branch information
Showing
10 changed files
with
594 additions
and
1 deletion.
There are no files selected for viewing
65 changes: 65 additions & 0 deletions
65
packages/cli/src/PublicApi/v1/handlers/projects/projects.handler.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import { globalScope, isLicensed, validCursor } from '../../shared/middlewares/global.middleware'; | ||
import type { Response } from 'express'; | ||
import type { ProjectRequest } from '@/requests'; | ||
import type { PaginatedRequest } from '@/PublicApi/types'; | ||
import Container from 'typedi'; | ||
import { ProjectController } from '@/controllers/project.controller'; | ||
import { ProjectRepository } from '@/databases/repositories/project.repository'; | ||
import { encodeNextCursor } from '../../shared/services/pagination.service'; | ||
|
||
type Create = ProjectRequest.Create; | ||
type Update = ProjectRequest.Update; | ||
type Delete = ProjectRequest.Delete; | ||
type GetAll = PaginatedRequest; | ||
|
||
export = { | ||
createProject: [ | ||
isLicensed('feat:projectRole:admin'), | ||
globalScope('project:create'), | ||
async (req: Create, res: Response) => { | ||
const project = await Container.get(ProjectController).createProject(req); | ||
|
||
return res.status(201).json(project); | ||
}, | ||
], | ||
updateProject: [ | ||
isLicensed('feat:projectRole:admin'), | ||
globalScope('project:update'), | ||
async (req: Update, res: Response) => { | ||
await Container.get(ProjectController).updateProject(req); | ||
|
||
return res.status(204).send(); | ||
}, | ||
], | ||
deleteProject: [ | ||
isLicensed('feat:projectRole:admin'), | ||
globalScope('project:delete'), | ||
async (req: Delete, res: Response) => { | ||
await Container.get(ProjectController).deleteProject(req); | ||
|
||
return res.status(204).send(); | ||
}, | ||
], | ||
getProjects: [ | ||
isLicensed('feat:projectRole:admin'), | ||
globalScope('project:list'), | ||
validCursor, | ||
async (req: GetAll, res: Response) => { | ||
const { offset = 0, limit = 100 } = req.query; | ||
|
||
const [projects, count] = await Container.get(ProjectRepository).findAndCount({ | ||
skip: offset, | ||
take: limit, | ||
}); | ||
|
||
return res.json({ | ||
data: projects, | ||
nextCursor: encodeNextCursor({ | ||
offset, | ||
limit, | ||
numberOfTotalRecords: count, | ||
}), | ||
}); | ||
}, | ||
], | ||
}; |
43 changes: 43 additions & 0 deletions
43
packages/cli/src/PublicApi/v1/handlers/projects/spec/paths/projects.projectId.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
delete: | ||
x-eov-operation-id: deleteProject | ||
x-eov-operation-handler: v1/handlers/projects/projects.handler | ||
tags: | ||
- Projects | ||
summary: Delete a project | ||
description: Delete a project from your instance. | ||
parameters: | ||
- $ref: '../schemas/parameters/projectId.yml' | ||
responses: | ||
'204': | ||
description: Operation successful. | ||
'401': | ||
$ref: '../../../../shared/spec/responses/unauthorized.yml' | ||
'403': | ||
$ref: '../../../../shared/spec/responses/forbidden.yml' | ||
'404': | ||
$ref: '../../../../shared/spec/responses/notFound.yml' | ||
put: | ||
x-eov-operation-id: updateProject | ||
x-eov-operation-handler: v1/handlers/projects/projects.handler | ||
tags: | ||
- Project | ||
summary: Update a project | ||
description: Update a project. | ||
requestBody: | ||
description: Updated project object. | ||
content: | ||
application/json: | ||
schema: | ||
$ref: '../schemas/project.yml' | ||
required: true | ||
responses: | ||
'204': | ||
description: Operation successful. | ||
'400': | ||
$ref: '../../../../shared/spec/responses/badRequest.yml' | ||
'401': | ||
$ref: '../../../../shared/spec/responses/unauthorized.yml' | ||
'403': | ||
$ref: '../../../../shared/spec/responses/forbidden.yml' | ||
'404': | ||
$ref: '../../../../shared/spec/responses/notFound.yml' |
40 changes: 40 additions & 0 deletions
40
packages/cli/src/PublicApi/v1/handlers/projects/spec/paths/projects.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
post: | ||
x-eov-operation-id: createProject | ||
x-eov-operation-handler: v1/handlers/projects/projects.handler | ||
tags: | ||
- Projects | ||
summary: Create a project | ||
description: Create a project in your instance. | ||
requestBody: | ||
description: Payload for project to create. | ||
content: | ||
application/json: | ||
schema: | ||
$ref: '../schemas/project.yml' | ||
required: true | ||
responses: | ||
'201': | ||
description: Operation successful. | ||
'400': | ||
$ref: '../../../../shared/spec/responses/badRequest.yml' | ||
'401': | ||
$ref: '../../../../shared/spec/responses/unauthorized.yml' | ||
get: | ||
x-eov-operation-id: getProjects | ||
x-eov-operation-handler: v1/handlers/projects/projects.handler | ||
tags: | ||
- Projects | ||
summary: Retrieve projects | ||
description: Retrieve projects from your instance. | ||
parameters: | ||
- $ref: '../../../../shared/spec/parameters/limit.yml' | ||
- $ref: '../../../../shared/spec/parameters/cursor.yml' | ||
responses: | ||
'200': | ||
description: Operation successful. | ||
content: | ||
application/json: | ||
schema: | ||
$ref: '../schemas/projectList.yml' | ||
'401': | ||
$ref: '../../../../shared/spec/responses/unauthorized.yml' |
6 changes: 6 additions & 0 deletions
6
packages/cli/src/PublicApi/v1/handlers/projects/spec/schemas/parameters/projectId.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
name: projectId | ||
in: path | ||
description: The ID of the project. | ||
required: true | ||
schema: | ||
type: string |
13 changes: 13 additions & 0 deletions
13
packages/cli/src/PublicApi/v1/handlers/projects/spec/schemas/project.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
type: object | ||
additionalProperties: false | ||
required: | ||
- name | ||
properties: | ||
id: | ||
type: string | ||
readOnly: true | ||
name: | ||
type: string | ||
type: | ||
type: string | ||
readOnly: true |
11 changes: 11 additions & 0 deletions
11
packages/cli/src/PublicApi/v1/handlers/projects/spec/schemas/projectList.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
type: object | ||
properties: | ||
data: | ||
type: array | ||
items: | ||
$ref: './project.yml' | ||
nextCursor: | ||
type: string | ||
description: Paginate through projects by setting the cursor parameter to a nextCursor attribute returned by a previous request. Default value fetches the first "page" of the collection. | ||
nullable: true | ||
example: MTIzZTQ1NjctZTg5Yi0xMmQzLWE0NTYtNDI2NjE0MTc0MDA |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.