Skip to content

Commit

Permalink
feat(core): Support create, read, update, delete projects in Public A…
Browse files Browse the repository at this point in the history
…PI (#10269)
  • Loading branch information
ivov authored Aug 2, 2024
1 parent dc8c94d commit 489ce10
Show file tree
Hide file tree
Showing 10 changed files with 594 additions and 1 deletion.
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,
}),
});
},
],
};
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'
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'
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
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
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
6 changes: 6 additions & 0 deletions packages/cli/src/PublicApi/v1/openapi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ tags:
description: Operations about source control
- name: Variables
description: Operations about variables
- name: Projects
description: Operations about projects

paths:
/audit:
Expand Down Expand Up @@ -72,6 +74,10 @@ paths:
$ref: './handlers/variables/spec/paths/variables.yml'
/variables/{id}:
$ref: './handlers/variables/spec/paths/variables.id.yml'
/projects:
$ref: './handlers/projects/spec/paths/projects.yml'
/projects/{projectId}:
$ref: './handlers/projects/spec/paths/projects.projectId.yml'
components:
schemas:
$ref: './shared/spec/schemas/_index.yml'
Expand Down
Loading

0 comments on commit 489ce10

Please # to comment.