-
Notifications
You must be signed in to change notification settings - Fork 5
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
[Feature] - 여행기 제목 기준 검색 기능 구현 #302
Merged
Merged
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
cf4068e
feat: 여행기 제목 키워드 기준 검색 기능 구현
hangillee 3db9e0f
feat: 여행기 검색 기능을 위한 키워드 검증 예외 처리
hangillee f82b05e
feat: QueryDSL 의존성 추가
hangillee 1e06495
refactor: 예외 메시지 추출 로직 변경
hangillee 500f981
refactor: API 문서 설명 수정
hangillee 4da7057
test: 여행기 제목 키워드 검색 기능 테스트 작성
hangillee ff064a5
feat: 여행기 제목 키워드 기준 검색 기능 구현
hangillee 947e7dd
refactor: 추상화에 의존하도록 변경
hangillee 26ef51c
refactor: 필드 final 추가
hangillee 6cbfff7
refactor: DTO 변환 과정 개선
hangillee 50221e2
refactor: 필요 없어진 예외 처리 로직 제거
hangillee 2d103a6
refactor: 검색 키워드 request parameter DTO로 분리
hangillee 0d1c8c4
refactor: 검색 메소드 시그니처 리팩토링
hangillee 9483715
refactor: 여행기 조회 테스트 검증 대상 수정
hangillee 72e6149
Merge branch 'develop/be' into feature/be/#254
hangillee b0f0d4f
chore: 오타 수정
hangillee 74b5bef
refactor: pagination 관련 테스트 fixture 수정
hangillee 7dd62ca
fix: conflict 해결
hangillee dab43fb
refactor: 조회 쿼리에 정렬 및 페이지네이션 정보 추가
hangillee File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -59,8 +59,8 @@ void setUp() { | |
@Test | ||
void readTravelogues() { | ||
// given | ||
travelogueTestHelper.initTravelogueTestDate(member); | ||
travelogueTestHelper.initTravelogueTestDate(member); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 😓 오타의 주범 정말 죄송합니다 |
||
travelogueTestHelper.initTravelogueTestData(member); | ||
travelogueTestHelper.initTravelogueTestData(member); | ||
travelogueTestHelper.initTravelogueTestData(); | ||
|
||
// when & then | ||
|
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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
확인 👍