58 lines
2.7 KiB
TypeScript
58 lines
2.7 KiB
TypeScript
import { Controller, Get, Post, Patch, Delete, Param, Body, Query } from '@nestjs/common';
|
|
import { ApiTags, ApiOperation, ApiResponse, ApiParam, ApiQuery } from '@nestjs/swagger';
|
|
import { ProjectService } from '../providers/project.service';
|
|
import { CreateProjectDto } from '../dto/project/create-project.dto';
|
|
import { UpdateProjectDto } from '../dto/project/update-project.dto';
|
|
import { TMProject } from '../entities/project.entity';
|
|
|
|
@ApiTags('Task Manager - Projects')
|
|
@Controller('task-manager/projects')
|
|
export class ProjectController {
|
|
constructor(private readonly projectService: ProjectService) {}
|
|
|
|
@Get()
|
|
@ApiOperation({ summary: 'Get all projects, optionally filtered by workspace' })
|
|
@ApiQuery({ name: 'workspaceId', required: false, description: 'Filter projects by workspace ID' })
|
|
@ApiResponse({ status: 200, description: 'List of projects', type: [TMProject] })
|
|
findAll(@Query('workspaceId') workspaceId?: string): Promise<TMProject[]> {
|
|
if (workspaceId) return this.projectService.findByWorkspace(workspaceId);
|
|
return this.projectService.findAll();
|
|
}
|
|
|
|
@Get(':id')
|
|
@ApiOperation({ summary: 'Get a project by ID' })
|
|
@ApiParam({ name: 'id', description: 'Project ID' })
|
|
@ApiResponse({ status: 200, description: 'Project found', type: TMProject })
|
|
@ApiResponse({ status: 404, description: 'Project not found' })
|
|
findOne(@Param('id') id: string): Promise<TMProject> {
|
|
return this.projectService.findOne(id);
|
|
}
|
|
|
|
@Post()
|
|
@ApiOperation({ summary: 'Create a new project' })
|
|
@ApiResponse({ status: 201, description: 'Project created', type: TMProject })
|
|
@ApiResponse({ status: 400, description: 'One or more users are not members of the workspace' })
|
|
@ApiResponse({ status: 404, description: 'Workspace not found' })
|
|
create(@Body() body: CreateProjectDto): Promise<TMProject> {
|
|
return this.projectService.create(body);
|
|
}
|
|
|
|
@Patch(':id')
|
|
@ApiOperation({ summary: 'Update a project' })
|
|
@ApiParam({ name: 'id', description: 'Project ID' })
|
|
@ApiResponse({ status: 200, description: 'Project updated', type: TMProject })
|
|
@ApiResponse({ status: 400, description: 'One or more users are not members of the workspace' })
|
|
@ApiResponse({ status: 404, description: 'Project not found' })
|
|
update(@Param('id') id: string, @Body() body: UpdateProjectDto): Promise<TMProject> {
|
|
return this.projectService.update(id, body);
|
|
}
|
|
|
|
@Delete(':id')
|
|
@ApiOperation({ summary: 'Delete a project' })
|
|
@ApiParam({ name: 'id', description: 'Project ID' })
|
|
@ApiResponse({ status: 200, description: 'Project deleted' })
|
|
@ApiResponse({ status: 404, description: 'Project not found' })
|
|
remove(@Param('id') id: string): Promise<TMProject> {
|
|
return this.projectService.remove(id);
|
|
}
|
|
} |