From 8fece0d147c906eafa6829890f049d3e4105be11 Mon Sep 17 00:00:00 2001 From: kmi0817 Date: Fri, 19 Apr 2024 23:53:15 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=EA=B2=8C=EC=8B=9C=EA=B8=80=20=EA=B2=80?= =?UTF-8?q?=EC=83=89=20=EC=8B=9C=20=EC=B0=A8=EB=8B=A8=ED=95=9C=20=ED=9A=8C?= =?UTF-8?q?=EC=9B=90=EC=9D=98=20=EA=B2=8C=EC=8B=9C=EA=B8=80=EC=9D=80=20?= =?UTF-8?q?=EC=A0=9C=EC=99=B8=ED=95=98=EB=8F=84=EB=A1=9D=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- BE/src/postings/postings.controller.ts | 5 +++-- BE/src/postings/postings.service.ts | 11 ++++++++++- BE/src/postings/repositories/postings.repository.ts | 10 +++++++++- 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/BE/src/postings/postings.controller.ts b/BE/src/postings/postings.controller.ts index 8eba7d7..caf99c6 100644 --- a/BE/src/postings/postings.controller.ts +++ b/BE/src/postings/postings.controller.ts @@ -96,8 +96,9 @@ export class PostingsController { description: '검색어와 선택 태그의 교집합에 해당하는 게시글을 반환합니다.', }) @ApiOkResponse({ schema: { example: search_OK } }) - async search(@Query() searchPostingDto: SearchPostingDto) { - return this.postingsService.findAll(searchPostingDto); + async search(@Req() request, @Query() searchPostingDto: SearchPostingDto) { + const userId = request['user'].id; + return this.postingsService.findAll(userId, searchPostingDto); } @Get('titles') diff --git a/BE/src/postings/postings.service.ts b/BE/src/postings/postings.service.ts index 577c2fa..f329d5b 100644 --- a/BE/src/postings/postings.service.ts +++ b/BE/src/postings/postings.service.ts @@ -18,11 +18,13 @@ import { Report } from './entities/report.entity'; import { Period, Season } from './postings.types'; import { BLOCKING_LIMIT } from './postings.constants'; import { StorageService } from 'src/storage/storage.service'; +import { BlockRepository } from 'src/users/block.repository'; @Injectable() export class PostingsService { constructor( private readonly userRepository: UserRepository, + private readonly blockRepository: BlockRepository, private readonly postingsRepository: PostingsRepository, private readonly likedsRepository: LikedsRepository, private readonly reportsRepository: ReportsRepository, @@ -44,8 +46,10 @@ export class PostingsService { return this.postingsRepository.save(posting); } - async findAll(dto: SearchPostingDto) { + async findAll(userId: string, dto: SearchPostingDto) { + const blockedIds = await this.findBlockedIds(userId); const postings = await this.postingsRepository.findAll( + blockedIds, dto.keyword, dto.sorting, dto.offset, @@ -226,4 +230,9 @@ export class PostingsService { reports: posting.reports, }; } + + private async findBlockedIds(blocker: string) { + const blocks = await this.blockRepository.findByBlocker(blocker); + return blocks.map((block) => block.blocked.id); + } } diff --git a/BE/src/postings/repositories/postings.repository.ts b/BE/src/postings/repositories/postings.repository.ts index 7c4c280..732be33 100644 --- a/BE/src/postings/repositories/postings.repository.ts +++ b/BE/src/postings/repositories/postings.repository.ts @@ -36,6 +36,7 @@ export class PostingsRepository { } async findAll( + blockedIds: string[], keyword: string, sorting: Sorting, offset: number, @@ -50,7 +51,14 @@ export class PostingsRepository { withWhos: WithWho[] ) { const conditions = ['p.title LIKE :keyword']; - let params: { [key: string]: string } = { keyword: `%${keyword}%` }; + let params: { [key: string]: string | string[] } = { + keyword: `%${keyword}%`, + }; + + if (blockedIds.length > 0) { + conditions.push('p.writer NOT IN (:...blockedIds)'); + params = { ...params, blockedIds }; + } if (budget) { conditions.push('p.budget = :budget');