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

feat: 검색 #28

Merged
merged 6 commits into from
Jan 20, 2024
Merged

feat: 검색 #28

merged 6 commits into from
Jan 20, 2024

Conversation

yoonsseo
Copy link
Member

PR

PR 요약

  • 검색 페이지 브랜드 검색 및 향수 검색

변경된 점

  1. 브랜드 검색과 향수 검색 구현
  2. 스웨거 적용
  3. 검색어 없는 경우 에러 처리

이슈 번호

fragrance.thumbnail,
fragrance.name.as("fragranceName"),
fragrance.brand.korName
)).distinct()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

오 저는 selectDistinct()로 했는데 따로 해도 되는군요!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

selectDistinct()로 해도 되는군용!!😆😆



@Override
public Page<BrandInfo> searchBrand(String search, Pageable pageable) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

검색하는 String이 korName or engName에 포함되는 건지 조회하는 거라면 List findByKorNameContainingIgnoreCaseOrEngNameContainingIgnoreCase(String korName, String engName); 으로는 안될까요?🤔

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

영어 이름과 한글 이름을 한 번에 확인하는 메소드로 빼는 것은 좋은 방법같아요!
하지만 너무 긴 이름은 오히려 좋지 않을 것 같아서 brandNameContains() 정도가 적당할 것 같네욤

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

앗 혹시 JpaRepository에서 조회하는 방법을 말하셨던 걸까욥?!

JpaRepository의 메소드 이름 규칙을 통해 메소드 이름만 지으면 JpaRepository가 알아서 쿼리를 짜주는 방법은
반환 타입이 해당 리포지토리의 타입(엔티티)일 경우에만 적용되는 것 같고

JpaRepository에서 DTO로 조회하려면

@Query(
    "SELECT new server.acode.domain.fragrance.dto.response.BrandInfo(b.brand_id, b.kor_name, b.round_img) " +
    " FROM Brand b " + 
    "WHERE b.kor_name = :search OR b.eng_name = :search")
Page<BrandInfo> searchBrand(@Param("search") String search, Pageable pageable);

이런 식으로 DTO의 경로를 적어주어야 한다고 하네용

사실 그냥 쿼리dsl을 사용했는데
찾아보고 나니 쿼리dsl을 사용하길 잘한 것 같다는 생각이 드네욥..! 😂😂

@yoonsseo yoonsseo merged commit 5ea91f7 into main Jan 20, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants