-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Feature] - 여행기 제목 기준 검색 기능 구현 (#302)
* feat: 여행기 제목 키워드 기준 검색 기능 구현 * feat: 여행기 검색 기능을 위한 키워드 검증 예외 처리 * feat: QueryDSL 의존성 추가 * refactor: 예외 메시지 추출 로직 변경 * refactor: API 문서 설명 수정 * test: 여행기 제목 키워드 검색 기능 테스트 작성 * feat: 여행기 제목 키워드 기준 검색 기능 구현 * refactor: 추상화에 의존하도록 변경 * refactor: 필드 final 추가 * refactor: DTO 변환 과정 개선 * refactor: 필요 없어진 예외 처리 로직 제거 * refactor: 검색 키워드 request parameter DTO로 분리 * refactor: 검색 메소드 시그니처 리팩토링 * refactor: 여행기 조회 테스트 검증 대상 수정 * chore: 오타 수정 * refactor: pagination 관련 테스트 fixture 수정 * fix: conflict 해결 * refactor: 조회 쿼리에 정렬 및 페이지네이션 정보 추가
- Loading branch information
Showing
15 changed files
with
260 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
backend/src/main/java/kr/touroot/global/config/QueryDslConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package kr.touroot.global.config; | ||
|
||
import com.querydsl.jpa.impl.JPAQueryFactory; | ||
import jakarta.persistence.EntityManager; | ||
import jakarta.persistence.PersistenceContext; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
@RequiredArgsConstructor | ||
@Configuration | ||
public class QueryDslConfig { | ||
|
||
@PersistenceContext | ||
private final EntityManager entityManager; | ||
|
||
@Bean | ||
public JPAQueryFactory jpaQueryFactory() { | ||
return new JPAQueryFactory(entityManager); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
backend/src/main/java/kr/touroot/travelogue/dto/request/TravelogueSearchRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package kr.touroot.travelogue.dto.request; | ||
|
||
import jakarta.validation.constraints.NotBlank; | ||
import jakarta.validation.constraints.Size; | ||
|
||
public record TravelogueSearchRequest( | ||
@NotBlank(message = "검색어는 2글자 이상이어야 합니다.") | ||
@Size(min = 2, message = "검색어는 2글자 이상이어야 합니다.") | ||
String keyword | ||
) { | ||
} |
10 changes: 10 additions & 0 deletions
10
backend/src/main/java/kr/touroot/travelogue/repository/TravelogueQueryRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package kr.touroot.travelogue.repository; | ||
|
||
import kr.touroot.travelogue.domain.Travelogue; | ||
import org.springframework.data.domain.Page; | ||
import org.springframework.data.domain.Pageable; | ||
|
||
public interface TravelogueQueryRepository { | ||
|
||
Page<Travelogue> findByTitleContaining(String keyword, Pageable pageable); | ||
} |
33 changes: 33 additions & 0 deletions
33
backend/src/main/java/kr/touroot/travelogue/repository/TravelogueQueryRepositoryImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package kr.touroot.travelogue.repository; | ||
|
||
import static kr.touroot.travelogue.domain.QTravelogue.travelogue; | ||
|
||
import com.querydsl.core.types.dsl.Expressions; | ||
import com.querydsl.jpa.impl.JPAQueryFactory; | ||
import java.util.List; | ||
import kr.touroot.travelogue.domain.Travelogue; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.data.domain.Page; | ||
import org.springframework.data.domain.PageImpl; | ||
import org.springframework.data.domain.Pageable; | ||
import org.springframework.stereotype.Repository; | ||
|
||
@RequiredArgsConstructor | ||
@Repository | ||
public class TravelogueQueryRepositoryImpl implements TravelogueQueryRepository { | ||
|
||
private final JPAQueryFactory jpaQueryFactory; | ||
|
||
@Override | ||
public Page<Travelogue> findByTitleContaining(String keyword, Pageable pageable) { | ||
List<Travelogue> results = jpaQueryFactory.selectFrom(travelogue) | ||
.where(Expressions.stringTemplate("replace({0}, ' ', '')", travelogue.title) | ||
.containsIgnoreCase(keyword.replace(" ", ""))) | ||
.orderBy(travelogue.id.desc()) | ||
.offset(pageable.getOffset()) | ||
.limit(pageable.getPageSize()) | ||
.fetch(); | ||
|
||
return new PageImpl<>(results, pageable, results.size()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
backend/src/test/java/kr/touroot/global/config/TestQueryDslConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package kr.touroot.global.config; | ||
|
||
import com.querydsl.jpa.impl.JPAQueryFactory; | ||
import jakarta.persistence.EntityManager; | ||
import jakarta.persistence.PersistenceContext; | ||
import kr.touroot.travelogue.repository.TravelogueQueryRepository; | ||
import kr.touroot.travelogue.repository.TravelogueQueryRepositoryImpl; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.boot.test.context.TestConfiguration; | ||
import org.springframework.context.annotation.Bean; | ||
|
||
@RequiredArgsConstructor | ||
@TestConfiguration | ||
public class TestQueryDslConfig { | ||
|
||
@PersistenceContext | ||
private final EntityManager entityManager; | ||
|
||
@Bean | ||
public JPAQueryFactory jpaQueryFactory() { | ||
return new JPAQueryFactory(entityManager); | ||
} | ||
|
||
@Bean | ||
public TravelogueQueryRepository travelogueQueryRepository() { | ||
return new TravelogueQueryRepositoryImpl(jpaQueryFactory()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.