feat(projects): add Swagger decorators for API documentation in ProjectsController

This commit is contained in:
Mathis HERRIOT 2025-05-17 00:12:49 +02:00
parent 1308e9c599
commit 3fe47795d9
No known key found for this signature in database
GPG Key ID: E7EB4A211D8D4907

View File

@ -11,10 +11,12 @@ import {
Query,
Res,
} from '@nestjs/common';
import { ApiTags, ApiOperation, ApiResponse, ApiParam, ApiQuery } from '@nestjs/swagger';
import { ProjectsService } from '../services/projects.service';
import { CreateProjectDto } from '../dto/create-project.dto';
import { UpdateProjectDto } from '../dto/update-project.dto';
@ApiTags('projects')
@Controller('projects')
export class ProjectsController {
constructor(private readonly projectsService: ProjectsService) {}
@ -22,6 +24,9 @@ export class ProjectsController {
/**
* 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()
@HttpCode(HttpStatus.CREATED)
create(@Body() createProjectDto: CreateProjectDto) {
@ -31,6 +36,9 @@ export class ProjectsController {
/**
* 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()
findAll(@Query('ownerId') ownerId?: string) {
if (ownerId) {
@ -42,6 +50,10 @@ export class ProjectsController {
/**
* 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')
findOne(@Param('id') id: string) {
return this.projectsService.findById(id);
@ -50,6 +62,11 @@ export class ProjectsController {
/**
* 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')
update(@Param('id') id: string, @Body() updateProjectDto: UpdateProjectDto) {
return this.projectsService.update(id, updateProjectDto);
@ -58,6 +75,10 @@ export class ProjectsController {
/**
* 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')
@HttpCode(HttpStatus.NO_CONTENT)
remove(@Param('id') id: string) {
@ -67,6 +88,11 @@ export class ProjectsController {
/**
* 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')
async checkUserAccess(
@Param('id') id: string,
@ -81,6 +107,11 @@ export class ProjectsController {
/**
* 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')
@HttpCode(HttpStatus.CREATED)
addCollaborator(@Param('id') id: string, @Param('userId') userId: string) {
@ -90,6 +121,11 @@ export class ProjectsController {
/**
* 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')
@HttpCode(HttpStatus.NO_CONTENT)
removeCollaborator(@Param('id') id: string, @Param('userId') userId: string) {
@ -99,6 +135,10 @@ export class ProjectsController {
/**
* 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')
getCollaborators(@Param('id') id: string) {
return this.projectsService.getCollaborators(id);