💜 Today I Learned

[개인과제]

해당 키워드를 body에 작성하면 키워드가 포함된 공연들이 뜨도록 하고 싶었다.
<작성 코드>

  • 서비스
async searchShow(keyword: string): Promise<any[]> {
    const filteredShows = await this.searchShowsByKeyword(keyword);
    return filteredShows;
  }
  private async selectShowById(id: number) {
    const show = await this.showRepository.findOneBy({ id });
    if (_.isNil(show)) {
      throw new NotFoundException('존재하지 않는 공연입니다.');
    }
    return show;
  }
  • searchShowsByKeyword 메서드
private async searchShowsByKeyword(keyword: string): Promise<Show[]> {
    const query = this.showRepository.createQueryBuilder('show');

    // 키워드에 해당하는 show 필터링
    query.where('LOWER(show.title) LIKE :keyword', {
      keyword: `%${keyword.toLowerCase()}%`,
    });

    // 검색 결과 반환
    return query.getMany();
  }

작성은 했지만 잘 실행이 되는지는 모르겠다..

0개의 댓글