From e0005d136da57ff0371c61900f8537ebb1e7a1b4 Mon Sep 17 00:00:00 2001 From: sumin Date: Wed, 21 May 2025 20:18:04 +0900 Subject: [PATCH] =?UTF-8?q?#5=20:recycle:=20[Refactor]=20:=20=EB=A1=9C?= =?UTF-8?q?=EC=A7=81=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/domain/feed/controller/feed.controller.ts | 4 +-- src/domain/match/match.module.ts | 3 ++- src/domain/match/match.service.ts | 26 +++++++++++++------ 3 files changed, 22 insertions(+), 11 deletions(-) diff --git a/src/domain/feed/controller/feed.controller.ts b/src/domain/feed/controller/feed.controller.ts index 23d3a17..9f213ef 100644 --- a/src/domain/feed/controller/feed.controller.ts +++ b/src/domain/feed/controller/feed.controller.ts @@ -124,8 +124,8 @@ export class FeedController { }, }) @Get('all-urls') - @ApiBearerAuth() - @UseGuards(JwtAuthGuard) + // @ApiBearerAuth() + // @UseGuards(JwtAuthGuard) async getAllFeedUrls(@Req() req): Promise> { const feeds = await this.feedService.getAllFeedUrls(); return ResponseDto.ok(feeds); diff --git a/src/domain/match/match.module.ts b/src/domain/match/match.module.ts index 1399f96..6de7501 100644 --- a/src/domain/match/match.module.ts +++ b/src/domain/match/match.module.ts @@ -7,10 +7,11 @@ import { DatabaseModule } from '../../global/database/module/database.module'; import { FeedRepository } from '../feed/repository/feed.repository'; import { MatchingResult } from './entity/matching-result.entity'; import { UsersModule } from '../users/module/users.module'; +import { MinioService } from '../s3/service/minio.service'; @Module({ imports: [DatabaseModule, UsersModule, TypeOrmModule.forFeature([MatchingResult ,Feed,])], controllers: [MatchController], - providers: [MatchService, FeedRepository], + providers: [MatchService, FeedRepository, MinioService], }) export class MatchModule {} diff --git a/src/domain/match/match.service.ts b/src/domain/match/match.service.ts index 13140de..9b6a53e 100644 --- a/src/domain/match/match.service.ts +++ b/src/domain/match/match.service.ts @@ -8,6 +8,7 @@ import { ErrorCode } from '../../global/exception/error-code'; import { CommonException } from '../../global/exception/common-exception'; import { FeedRepository } from '../feed/repository/feed.repository'; import { UserRepository } from '../users/repository/user.repository'; +import { MinioService } from '../s3/service/minio.service'; @Injectable() export class MatchService { @@ -16,6 +17,7 @@ export class MatchService { private readonly matchingResultRepository: Repository, private feedRepository: FeedRepository, private userRepository: UserRepository, + private readonly minioService: MinioService, ) {} async createMatchingResultsBulk( @@ -91,7 +93,7 @@ export class MatchService { async getHighSimilarityFindersForProtector( userId: number, - ): Promise<{ finderId: number; message: string }[]> { + ): Promise<{ finderId: number; message: string; presigned_url: string }[]> { // 1. 보호자가 작성한 feed 목록 조회 const feeds = await this.feedRepository.find({ where: { author: { id: userId } }, @@ -103,19 +105,27 @@ export class MatchService { return []; } - // 2. 해당 feedId에 대한 similarity 80 이상인 MatchingResult 조회 + // 2. 해당 feedId에 대한 similarity 80 이상인 MatchingResult 조회 (feed, user, feed.fileName 필요) const matchingResults = await this.matchingResultRepository.find({ where: { feed: { id: In(feedIds) }, similarity: MoreThanOrEqual(80), }, - relations: ['user'], // 발견자 정보 + relations: ['user', 'feed'], }); - // 3. 발견자 id와 메시지만 추출해서 반환 - return matchingResults.map((result) => ({ - finderId: result.user.id, - message: `유사도${result.similarity}인 제보가 들어왔어요!`, - })); + // 3. presigned_url 발급 및 결과 생성 + return Promise.all( + matchingResults.map(async (result) => { + // presigned_url 발급 (feed.fileName 사용) + const presigned = await this.minioService.getPresignedUrlForDownload(result.feed.fileName); + return { + finderId: result.user.id, + message: `유사도${result.similarity}인 제보가 들어왔어요!`, + presigned_url: presigned.url, + }; + }), + ); } + }