feat: added attachment controller

This commit is contained in:
2026-07-02 12:59:33 +03:30
parent fc23a94fb6
commit 4b95d35d87
@@ -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<TMAttachment[]> {
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<TMAttachment> {
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<TMAttachment> {
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<TMAttachment> {
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<void> {
return this.attachmentService.remove(id);
}
}