Skip to content

Commit

Permalink
feat: 게시글 검색 시 차단한 회원의 게시글은 제외하도록 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
kmi0817 committed Apr 19, 2024
1 parent ed0c0e0 commit 8fece0d
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 deletions.
5 changes: 3 additions & 2 deletions BE/src/postings/postings.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
11 changes: 10 additions & 1 deletion BE/src/postings/postings.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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);
}
}
10 changes: 9 additions & 1 deletion BE/src/postings/repositories/postings.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export class PostingsRepository {
}

async findAll(
blockedIds: string[],
keyword: string,
sorting: Sorting,
offset: number,
Expand All @@ -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');
Expand Down

0 comments on commit 8fece0d

Please sign in to comment.