Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor: method name #54

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/article/article.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ export class ArticleController {
description: '검색을 위한 검색어를 담고 있습니다',
example: '뇽뇽',
})
async findAll(
async search(
@Query('search') search: string,
@UserRequest() { userId }: UserPayload,
): Promise<ManyArticlesResponseDto> {
const articles: Article[] = await this.articleService.findAll(userId, search);
const articles: Article[] = await this.articleService.search(userId, search);
return { articles };
}

Expand Down
8 changes: 2 additions & 6 deletions src/article/article.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,10 @@ export class ArticleService {
return await this.articleRepository.softDelete(ids);
}

async findAll(userId: number, search: string): Promise<Article[]> {
async search(userId: number, search: string): Promise<Article[]> {
const blacklists = await this.blacklistRepository.findAllBlacklistByUserId(userId);
const blacklistIds: number[] = blacklists.map((it) => it.targetId);
const articles: Article[] = await this.articleRepository
.createQueryBuilder('article')
.where('article.title LIKE :search', { search })
.where('article.content LIKE :search', { search })
.getMany();
const articles: Article[] = await this.articleRepository.search(search);
return articles.filter((article) => !blacklistIds.includes(article.userId));
}

Expand Down
7 changes: 7 additions & 0 deletions src/article/repository/article.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,11 @@ export class ArticleRepository extends Repository<Article> {
constructor(private readonly dataSource: DataSource) {
super(Article, dataSource.createEntityManager(), dataSource.createQueryRunner());
}

async search(search: string): Promise<Article[]> {
return await this.createQueryBuilder('article')
.where('article.title LIKE :search', { search })
.where('article.content LIKE :search', { search })
.getMany();
}
}