Files
dating-app-backend/src/modules/media/media.controller.ts
Oscar cd98f04987 feat(database-schema): добавляет ссылку на активный чат в схему профиля пользователя
 feat(likes.service): обновляет логику создания лайков с учетом активного чата

 feat(likes.module): импортирует модуль Gateways для работы с чатами

 feat(feed.service): добавляет условие для фильтрации профилей без активного чата

 feat(storage.service): устанавливает политику доступа к бакету S3 для получения объектов

 feat(likes-response.dto): добавляет поле чата в ответ на лайк

 feat(media.controller): добавляет описание для загрузки медиафайлов

 feat(chat.service): добавляет возможность закрытия чата с отчетом или сообщением

 feat(chat.controller): обновляет метод закрытия чата для обработки отчетов

 feat(app.module): добавляет модуль Dev для разработки в не продакшн среде
2026-06-09 15:39:38 +03:00

64 lines
2.1 KiB
TypeScript

import { Controller, Delete, Get, Param, Post, Query, Req, UseGuards } from '@nestjs/common';
import { ApiBearerAuth, ApiBody, ApiConsumes, ApiCreatedResponse, ApiOkResponse, ApiOperation, ApiTags } from '@nestjs/swagger';
import { FastifyRequest } from 'fastify';
import { CurrentUser } from '../../common/decorators/current-user.decorator';
import { JwtAuthGuard } from '../../common/guards/jwt-auth.guard';
import { MediaService } from './media.service';
import { MediaItemDto } from '../profiles/dto/profile-response.dto';
import { MessageResponseDto } from '../../common/dto/message-response.dto';
@ApiTags('media')
@ApiBearerAuth()
@UseGuards(JwtAuthGuard)
@Controller('profiles/:profileId/media')
export class MediaController {
constructor(private readonly mediaService: MediaService) {}
@Post('upload')
@ApiOperation({ summary: 'Upload photo / video / audio to profile' })
@ApiConsumes('multipart/form-data')
@ApiBody({
schema: {
type: 'object',
required: ['file'],
properties: {
file: { type: 'string', format: 'binary' },
},
},
})
@ApiCreatedResponse({ type: MediaItemDto })
async upload(
@CurrentUser('id') userId: string,
@Param('profileId') profileId: string,
@Req() req: FastifyRequest,
@Query('type') type: 'photo' | 'video' | 'audio' = 'photo',
) {
const data = await (req as any).file();
if (!data) throw new Error('No file provided');
const buffer = await data.toBuffer();
return this.mediaService.upload(
userId,
profileId,
{ buffer, originalname: data.filename, mimetype: data.mimetype },
type,
);
}
@Get()
@ApiOperation({ summary: 'Get all media for a profile' })
@ApiOkResponse({ type: [MediaItemDto] })
getMedia(@Param('profileId') profileId: string) {
return this.mediaService.getByProfileId(profileId);
}
@Delete(':mediaId')
@ApiOperation({ summary: 'Delete media item' })
@ApiOkResponse({ type: MessageResponseDto })
deleteMedia(
@CurrentUser('id') userId: string,
@Param('mediaId') mediaId: string,
) {
return this.mediaService.delete(userId, mediaId);
}
}