feat(projects): add Swagger decorators for API documentation in ProjectsController
This commit is contained in:
parent
1308e9c599
commit
3fe47795d9
@ -11,10 +11,12 @@ import {
|
|||||||
Query,
|
Query,
|
||||||
Res,
|
Res,
|
||||||
} from '@nestjs/common';
|
} from '@nestjs/common';
|
||||||
|
import { ApiTags, ApiOperation, ApiResponse, ApiParam, ApiQuery } from '@nestjs/swagger';
|
||||||
import { ProjectsService } from '../services/projects.service';
|
import { ProjectsService } from '../services/projects.service';
|
||||||
import { CreateProjectDto } from '../dto/create-project.dto';
|
import { CreateProjectDto } from '../dto/create-project.dto';
|
||||||
import { UpdateProjectDto } from '../dto/update-project.dto';
|
import { UpdateProjectDto } from '../dto/update-project.dto';
|
||||||
|
|
||||||
|
@ApiTags('projects')
|
||||||
@Controller('projects')
|
@Controller('projects')
|
||||||
export class ProjectsController {
|
export class ProjectsController {
|
||||||
constructor(private readonly projectsService: ProjectsService) {}
|
constructor(private readonly projectsService: ProjectsService) {}
|
||||||
@ -22,6 +24,9 @@ export class ProjectsController {
|
|||||||
/**
|
/**
|
||||||
* Create a new project
|
* Create a new project
|
||||||
*/
|
*/
|
||||||
|
@ApiOperation({ summary: 'Create a new project' })
|
||||||
|
@ApiResponse({ status: 201, description: 'The project has been successfully created.' })
|
||||||
|
@ApiResponse({ status: 400, description: 'Bad request.' })
|
||||||
@Post()
|
@Post()
|
||||||
@HttpCode(HttpStatus.CREATED)
|
@HttpCode(HttpStatus.CREATED)
|
||||||
create(@Body() createProjectDto: CreateProjectDto) {
|
create(@Body() createProjectDto: CreateProjectDto) {
|
||||||
@ -31,6 +36,9 @@ export class ProjectsController {
|
|||||||
/**
|
/**
|
||||||
* Get all projects or filter by owner ID
|
* Get all projects or filter by owner ID
|
||||||
*/
|
*/
|
||||||
|
@ApiOperation({ summary: 'Get all projects or filter by owner ID' })
|
||||||
|
@ApiResponse({ status: 200, description: 'Return all projects or projects for a specific owner.' })
|
||||||
|
@ApiQuery({ name: 'ownerId', required: false, description: 'Filter projects by owner ID' })
|
||||||
@Get()
|
@Get()
|
||||||
findAll(@Query('ownerId') ownerId?: string) {
|
findAll(@Query('ownerId') ownerId?: string) {
|
||||||
if (ownerId) {
|
if (ownerId) {
|
||||||
@ -42,6 +50,10 @@ export class ProjectsController {
|
|||||||
/**
|
/**
|
||||||
* Get a project by ID
|
* Get a project by ID
|
||||||
*/
|
*/
|
||||||
|
@ApiOperation({ summary: 'Get a project by ID' })
|
||||||
|
@ApiResponse({ status: 200, description: 'Return the project.' })
|
||||||
|
@ApiResponse({ status: 404, description: 'Project not found.' })
|
||||||
|
@ApiParam({ name: 'id', description: 'The ID of the project' })
|
||||||
@Get(':id')
|
@Get(':id')
|
||||||
findOne(@Param('id') id: string) {
|
findOne(@Param('id') id: string) {
|
||||||
return this.projectsService.findById(id);
|
return this.projectsService.findById(id);
|
||||||
@ -50,6 +62,11 @@ export class ProjectsController {
|
|||||||
/**
|
/**
|
||||||
* Update a project
|
* Update a project
|
||||||
*/
|
*/
|
||||||
|
@ApiOperation({ summary: 'Update a project' })
|
||||||
|
@ApiResponse({ status: 200, description: 'The project has been successfully updated.' })
|
||||||
|
@ApiResponse({ status: 400, description: 'Bad request.' })
|
||||||
|
@ApiResponse({ status: 404, description: 'Project not found.' })
|
||||||
|
@ApiParam({ name: 'id', description: 'The ID of the project' })
|
||||||
@Patch(':id')
|
@Patch(':id')
|
||||||
update(@Param('id') id: string, @Body() updateProjectDto: UpdateProjectDto) {
|
update(@Param('id') id: string, @Body() updateProjectDto: UpdateProjectDto) {
|
||||||
return this.projectsService.update(id, updateProjectDto);
|
return this.projectsService.update(id, updateProjectDto);
|
||||||
@ -58,6 +75,10 @@ export class ProjectsController {
|
|||||||
/**
|
/**
|
||||||
* Delete a project
|
* Delete a project
|
||||||
*/
|
*/
|
||||||
|
@ApiOperation({ summary: 'Delete a project' })
|
||||||
|
@ApiResponse({ status: 204, description: 'The project has been successfully deleted.' })
|
||||||
|
@ApiResponse({ status: 404, description: 'Project not found.' })
|
||||||
|
@ApiParam({ name: 'id', description: 'The ID of the project' })
|
||||||
@Delete(':id')
|
@Delete(':id')
|
||||||
@HttpCode(HttpStatus.NO_CONTENT)
|
@HttpCode(HttpStatus.NO_CONTENT)
|
||||||
remove(@Param('id') id: string) {
|
remove(@Param('id') id: string) {
|
||||||
@ -67,6 +88,11 @@ export class ProjectsController {
|
|||||||
/**
|
/**
|
||||||
* Check if a user has access to a project
|
* Check if a user has access to a project
|
||||||
*/
|
*/
|
||||||
|
@ApiOperation({ summary: 'Check if a user has access to a project' })
|
||||||
|
@ApiResponse({ status: 200, description: 'Returns true if the user has access, false otherwise.' })
|
||||||
|
@ApiResponse({ status: 404, description: 'Project not found.' })
|
||||||
|
@ApiParam({ name: 'id', description: 'The ID of the project' })
|
||||||
|
@ApiParam({ name: 'userId', description: 'The ID of the user' })
|
||||||
@Get(':id/check-access/:userId')
|
@Get(':id/check-access/:userId')
|
||||||
async checkUserAccess(
|
async checkUserAccess(
|
||||||
@Param('id') id: string,
|
@Param('id') id: string,
|
||||||
@ -81,6 +107,11 @@ export class ProjectsController {
|
|||||||
/**
|
/**
|
||||||
* Add a collaborator to a project
|
* Add a collaborator to a project
|
||||||
*/
|
*/
|
||||||
|
@ApiOperation({ summary: 'Add a collaborator to a project' })
|
||||||
|
@ApiResponse({ status: 201, description: 'The collaborator has been successfully added to the project.' })
|
||||||
|
@ApiResponse({ status: 404, description: 'Project or user not found.' })
|
||||||
|
@ApiParam({ name: 'id', description: 'The ID of the project' })
|
||||||
|
@ApiParam({ name: 'userId', description: 'The ID of the user to add as a collaborator' })
|
||||||
@Post(':id/collaborators/:userId')
|
@Post(':id/collaborators/:userId')
|
||||||
@HttpCode(HttpStatus.CREATED)
|
@HttpCode(HttpStatus.CREATED)
|
||||||
addCollaborator(@Param('id') id: string, @Param('userId') userId: string) {
|
addCollaborator(@Param('id') id: string, @Param('userId') userId: string) {
|
||||||
@ -90,6 +121,11 @@ export class ProjectsController {
|
|||||||
/**
|
/**
|
||||||
* Remove a collaborator from a project
|
* Remove a collaborator from a project
|
||||||
*/
|
*/
|
||||||
|
@ApiOperation({ summary: 'Remove a collaborator from a project' })
|
||||||
|
@ApiResponse({ status: 204, description: 'The collaborator has been successfully removed from the project.' })
|
||||||
|
@ApiResponse({ status: 404, description: 'Project or collaborator not found.' })
|
||||||
|
@ApiParam({ name: 'id', description: 'The ID of the project' })
|
||||||
|
@ApiParam({ name: 'userId', description: 'The ID of the user to remove as a collaborator' })
|
||||||
@Delete(':id/collaborators/:userId')
|
@Delete(':id/collaborators/:userId')
|
||||||
@HttpCode(HttpStatus.NO_CONTENT)
|
@HttpCode(HttpStatus.NO_CONTENT)
|
||||||
removeCollaborator(@Param('id') id: string, @Param('userId') userId: string) {
|
removeCollaborator(@Param('id') id: string, @Param('userId') userId: string) {
|
||||||
@ -99,6 +135,10 @@ export class ProjectsController {
|
|||||||
/**
|
/**
|
||||||
* Get all collaborators for a project
|
* Get all collaborators for a project
|
||||||
*/
|
*/
|
||||||
|
@ApiOperation({ summary: 'Get all collaborators for a project' })
|
||||||
|
@ApiResponse({ status: 200, description: 'Return all collaborators for the project.' })
|
||||||
|
@ApiResponse({ status: 404, description: 'Project not found.' })
|
||||||
|
@ApiParam({ name: 'id', description: 'The ID of the project' })
|
||||||
@Get(':id/collaborators')
|
@Get(':id/collaborators')
|
||||||
getCollaborators(@Param('id') id: string) {
|
getCollaborators(@Param('id') id: string) {
|
||||||
return this.projectsService.getCollaborators(id);
|
return this.projectsService.getCollaborators(id);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user