diff --git a/src/modules/task-manager/controllers/task.controller.ts b/src/modules/task-manager/controllers/task.controller.ts new file mode 100644 index 0000000..9e356b3 --- /dev/null +++ b/src/modules/task-manager/controllers/task.controller.ts @@ -0,0 +1,67 @@ +import { Controller, Get, Post, Patch, Delete, Param, Body, Query } from '@nestjs/common'; +import { ApiTags, ApiOperation, ApiResponse, ApiParam, ApiQuery } from '@nestjs/swagger'; +import { TaskService } from '../providers/task.service'; +import { CreateTaskDto } from '../dto/task/create-task.dto'; +import { UpdateTaskDto } from '../dto/task/update-task.dto'; +import { ChangeTaskPhaseDto } from '../dto/task/change-task-phase.dto'; +import { TMTask } from '../entities/task.entity'; + +@ApiTags('Task Manager - Tasks') +@Controller('task-manager/tasks') +export class TaskController { + constructor(private readonly taskService: TaskService) {} + + @Get() + @ApiOperation({ summary: 'Get all tasks, optionally filtered by phase' }) + @ApiQuery({ name: 'taskPhaseId', required: false, description: 'Filter tasks by task phase ID' }) + @ApiResponse({ status: 200, description: 'List of tasks', type: [TMTask] }) + findAll(@Query('taskPhaseId') taskPhaseId?: string): Promise { + if (taskPhaseId) return this.taskService.findByPhase(taskPhaseId); + return this.taskService.findAll(); + } + + @Get(':id') + @ApiOperation({ summary: 'Get a task by ID' }) + @ApiParam({ name: 'id', description: 'Task ID' }) + @ApiResponse({ status: 200, description: 'Task found', type: TMTask }) + @ApiResponse({ status: 404, description: 'Task not found' }) + findOne(@Param('id') id: string): Promise { + return this.taskService.findOne(id); + } + + @Post() + @ApiOperation({ summary: 'Create a new task' }) + @ApiResponse({ status: 201, description: 'Task created', type: TMTask }) + @ApiResponse({ status: 404, description: 'TaskPhase not found' }) + create(@Body() body: CreateTaskDto): Promise { + return this.taskService.create(body); + } + + @Patch(':id') + @ApiOperation({ summary: 'Update a task' }) + @ApiParam({ name: 'id', description: 'Task ID' }) + @ApiResponse({ status: 200, description: 'Task updated', type: TMTask }) + @ApiResponse({ status: 404, description: 'Task or TaskPhase not found' }) + update(@Param('id') id: string, @Body() body: UpdateTaskDto): Promise { + return this.taskService.update(id, body); + } + + @Patch(':id/change-phase') + @ApiOperation({ summary: 'Move a task to a different phase within the same project' }) + @ApiParam({ name: 'id', description: 'Task ID' }) + @ApiResponse({ status: 200, description: 'Task phase changed', type: TMTask }) + @ApiResponse({ status: 400, description: 'Target phase belongs to a different project' }) + @ApiResponse({ status: 404, description: 'Task or TaskPhase not found' }) + changePhase(@Param('id') id: string, @Body() body: ChangeTaskPhaseDto): Promise { + return this.taskService.changePhase(id, body); + } + + @Delete(':id') + @ApiOperation({ summary: 'Delete a task' }) + @ApiParam({ name: 'id', description: 'Task ID' }) + @ApiResponse({ status: 200, description: 'Task deleted' }) + @ApiResponse({ status: 404, description: 'Task not found' }) + remove(@Param('id') id: string): Promise { + return this.taskService.remove(id); + } +} \ No newline at end of file