From 4b95d35d874a88db1955c950f9e0f0866cd77c40 Mon Sep 17 00:00:00 2001 From: realrafi Date: Thu, 2 Jul 2026 12:59:33 +0330 Subject: [PATCH] feat: added attachment controller --- .../controllers/attachment.controller.ts | 56 +++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 src/modules/task-manager/controllers/attachment.controller.ts diff --git a/src/modules/task-manager/controllers/attachment.controller.ts b/src/modules/task-manager/controllers/attachment.controller.ts new file mode 100644 index 0000000..7c004a7 --- /dev/null +++ b/src/modules/task-manager/controllers/attachment.controller.ts @@ -0,0 +1,56 @@ +import { Controller, Get, Post, Patch, Delete, Param, Body, Query } from '@nestjs/common'; +import { ApiTags, ApiOperation, ApiResponse, ApiParam, ApiQuery } from '@nestjs/swagger'; +import { AttachmentService } from '../providers/attachment.service'; +import { CreateAttachmentDto } from '../dto/attachment/create-attachment.dto'; +import { UpdateAttachmentDto } from '../dto/attachment/update-attachment.dto'; +import { TMAttachment } from '../entities/attachment.entity'; + +@ApiTags('Task Manager - Attachments') +@Controller('task-manager/attachments') +export class AttachmentController { + constructor(private readonly attachmentService: AttachmentService) {} + + @Get() + @ApiOperation({ summary: 'Get all attachments, optionally filtered by task' }) + @ApiQuery({ name: 'taskId', required: false, description: 'Filter attachments by task ID' }) + @ApiResponse({ status: 200, description: 'List of attachments', type: [TMAttachment] }) + findAll(@Query('taskId') taskId?: string): Promise { + if (taskId) return this.attachmentService.findByTask(taskId); + return this.attachmentService.findAll(); + } + + @Get(':id') + @ApiOperation({ summary: 'Get an attachment by ID' }) + @ApiParam({ name: 'id', description: 'Attachment ID' }) + @ApiResponse({ status: 200, description: 'Attachment found', type: TMAttachment }) + @ApiResponse({ status: 404, description: 'Attachment not found' }) + findOne(@Param('id') id: string): Promise { + return this.attachmentService.findOne(id); + } + + @Post() + @ApiOperation({ summary: 'Create a new attachment' }) + @ApiResponse({ status: 201, description: 'Attachment created', type: TMAttachment }) + @ApiResponse({ status: 404, description: 'Task not found' }) + create(@Body() body: CreateAttachmentDto): Promise { + return this.attachmentService.create(body); + } + + @Patch(':id') + @ApiOperation({ summary: 'Update an attachment' }) + @ApiParam({ name: 'id', description: 'Attachment ID' }) + @ApiResponse({ status: 200, description: 'Attachment updated', type: TMAttachment }) + @ApiResponse({ status: 404, description: 'Attachment or Task not found' }) + update(@Param('id') id: string, @Body() body: UpdateAttachmentDto): Promise { + return this.attachmentService.update(id, body); + } + + @Delete(':id') + @ApiOperation({ summary: 'Delete an attachment' }) + @ApiParam({ name: 'id', description: 'Attachment ID' }) + @ApiResponse({ status: 200, description: 'Attachment deleted' }) + @ApiResponse({ status: 404, description: 'Attachment not found' }) + remove(@Param('id') id: string): Promise { + return this.attachmentService.remove(id); + } +} \ No newline at end of file