-
Notifications
You must be signed in to change notification settings - Fork 1
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] FAQ 검색기능 추가 #222
Merged
[feat] FAQ 검색기능 추가 #222
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
df9fdee
[feat] Querydsl 관련 의존성 추가
wnd01jun fe81866
[feat] 동적 쿼리를 담당하는 FaqSearchRepository 추가
wnd01jun fccb9ff
[feat] FaqService searchFaq 추가
wnd01jun f24d963
[feat] FaqApi findByPaging 파라미터 및 호출 메서드 변경
wnd01jun 16a3ee7
[feat] ErrorStatus Faq관련 status 추가
wnd01jun 9772e0f
[feat] FAQ, SearchKeyword 관련 API 추가
wnd01jun 64e64e3
[feat] Faq와 SearchKeyword의 중간 mapping 객체, FaqKeyword 추가
wnd01jun bd62f55
[feat] FaqKeyword repository, dto, test 추가
wnd01jun f6166e6
[feat] FaqService keyword 관련 로직 추가 및 테스트
wnd01jun f00df26
[feat] FaqSearchRepository의 동적 쿼리 로직 추가 (QueryDSL)
wnd01jun d78df08
[feat] SearchKeyword 관련 로직 추가
wnd01jun 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
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
10 changes: 10 additions & 0 deletions
10
src/main/java/com/bbteam/budgetbuddies/domain/faq/repository/FaqSearchRepository.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 com.bbteam.budgetbuddies.domain.faq.repository; | ||
|
||
import com.bbteam.budgetbuddies.domain.faq.entity.Faq; | ||
import org.springframework.data.domain.Page; | ||
import org.springframework.data.domain.Pageable; | ||
|
||
public interface FaqSearchRepository { | ||
|
||
Page<Faq> searchFaq(Pageable pageable, String searchCondition); | ||
} |
61 changes: 61 additions & 0 deletions
61
src/main/java/com/bbteam/budgetbuddies/domain/faq/repository/FaqSearchRepositoryImpl.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,61 @@ | ||
package com.bbteam.budgetbuddies.domain.faq.repository; | ||
|
||
import com.bbteam.budgetbuddies.domain.faq.entity.Faq; | ||
import com.bbteam.budgetbuddies.domain.searchkeyword.domain.QSearchKeyword; | ||
import com.querydsl.core.types.dsl.BooleanExpression; | ||
import com.querydsl.jpa.JPAExpressions; | ||
import com.querydsl.jpa.impl.JPAQueryFactory; | ||
import jakarta.persistence.EntityManager; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.data.domain.Page; | ||
import org.springframework.data.domain.PageImpl; | ||
import org.springframework.data.domain.Pageable; | ||
|
||
import java.util.List; | ||
|
||
import static com.bbteam.budgetbuddies.domain.faq.entity.QFaq.*; | ||
import static com.bbteam.budgetbuddies.domain.faqkeyword.domain.QFaqKeyword.*; | ||
import static com.bbteam.budgetbuddies.domain.searchkeyword.domain.QSearchKeyword.*; | ||
|
||
public class FaqSearchRepositoryImpl implements FaqSearchRepository{ | ||
|
||
private final JPAQueryFactory queryFactory; | ||
|
||
public FaqSearchRepositoryImpl(EntityManager em) { | ||
this.queryFactory = new JPAQueryFactory(em); | ||
} | ||
|
||
@Override | ||
public Page<Faq> searchFaq(Pageable pageable, String searchCondition) { | ||
List<Faq> result = queryFactory.select(faq) | ||
.from(faq) | ||
.where(faq.id.in( | ||
JPAExpressions | ||
.select(faqKeyword.faq.id) | ||
.from(faqKeyword) | ||
.join(searchKeyword).on(keywordMatch(searchCondition)) | ||
)) | ||
.offset(pageable.getOffset()) | ||
.limit(pageable.getPageSize()) | ||
.fetch(); | ||
|
||
Long total = queryFactory.select(faq.count()) | ||
.from(faq) | ||
.where(faq.id.in( | ||
JPAExpressions | ||
.select(faqKeyword.faq.id) | ||
.from(faqKeyword) | ||
.join(searchKeyword).on(keywordMatch(searchCondition)) | ||
)) | ||
.fetchOne(); | ||
|
||
return new PageImpl<>(result, pageable, total); | ||
|
||
} | ||
|
||
private BooleanExpression keywordMatch(String searchCondition) { | ||
return searchCondition != null ? searchKeyword.keyword.contains(searchCondition) : null; | ||
} | ||
|
||
} | ||
|
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
32 changes: 32 additions & 0 deletions
32
src/main/java/com/bbteam/budgetbuddies/domain/faqkeyword/domain/FaqKeyword.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,32 @@ | ||
package com.bbteam.budgetbuddies.domain.faqkeyword.domain; | ||
|
||
import com.bbteam.budgetbuddies.common.BaseEntity; | ||
import com.bbteam.budgetbuddies.domain.faq.entity.Faq; | ||
import com.bbteam.budgetbuddies.domain.searchkeyword.domain.SearchKeyword; | ||
import jakarta.persistence.Entity; | ||
import jakarta.persistence.FetchType; | ||
import jakarta.persistence.JoinColumn; | ||
import jakarta.persistence.ManyToOne; | ||
import lombok.*; | ||
import lombok.experimental.SuperBuilder; | ||
import org.hibernate.annotations.NotFound; | ||
import org.hibernate.annotations.NotFoundAction; | ||
|
||
@Entity | ||
@Getter | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
@AllArgsConstructor | ||
@SuperBuilder | ||
public class FaqKeyword extends BaseEntity { | ||
|
||
@ManyToOne(fetch = FetchType.LAZY) | ||
@JoinColumn(name = "faq_id") | ||
@NotFound(action = NotFoundAction.IGNORE) | ||
private Faq faq; | ||
|
||
@ManyToOne(fetch = FetchType.LAZY) | ||
@JoinColumn(name = "search_keyword_id") | ||
@NotFound(action = NotFoundAction.IGNORE) | ||
private SearchKeyword searchKeyword; | ||
|
||
} |
21 changes: 21 additions & 0 deletions
21
src/main/java/com/bbteam/budgetbuddies/domain/faqkeyword/dto/FaqKeywordResponseDto.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 com.bbteam.budgetbuddies.domain.faqkeyword.dto; | ||
|
||
import com.bbteam.budgetbuddies.domain.faqkeyword.domain.FaqKeyword; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
|
||
@AllArgsConstructor | ||
@Getter | ||
public class FaqKeywordResponseDto { | ||
|
||
private Long faqId; | ||
private Long searchKeywordId; | ||
|
||
private String faqTitle; | ||
private String keyword; | ||
|
||
public static FaqKeywordResponseDto toDto(FaqKeyword faqKeyword) { | ||
return new FaqKeywordResponseDto(faqKeyword.getFaq().getId(), faqKeyword.getSearchKeyword().getId(), | ||
faqKeyword.getFaq().getTitle(), faqKeyword.getSearchKeyword().getKeyword()); | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
...main/java/com/bbteam/budgetbuddies/domain/faqkeyword/repository/FaqKeywordRepository.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,12 @@ | ||
package com.bbteam.budgetbuddies.domain.faqkeyword.repository; | ||
|
||
import com.bbteam.budgetbuddies.domain.faq.entity.Faq; | ||
import com.bbteam.budgetbuddies.domain.faqkeyword.domain.FaqKeyword; | ||
import com.bbteam.budgetbuddies.domain.searchkeyword.domain.SearchKeyword; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
import java.util.Optional; | ||
|
||
public interface FaqKeywordRepository extends JpaRepository<FaqKeyword, Long> { | ||
Optional<FaqKeyword> findByFaqAndSearchKeyword(Faq faq, SearchKeyword searchKeyword); | ||
} |
48 changes: 48 additions & 0 deletions
48
...ava/com/bbteam/budgetbuddies/domain/searchkeyword/controller/SearchKeywordController.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,48 @@ | ||
package com.bbteam.budgetbuddies.domain.searchkeyword.controller; | ||
|
||
import com.bbteam.budgetbuddies.apiPayload.ApiResponse; | ||
import com.bbteam.budgetbuddies.domain.searchkeyword.domain.SearchKeyword; | ||
import com.bbteam.budgetbuddies.domain.searchkeyword.service.SearchKeywordService; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.data.domain.Page; | ||
import org.springframework.data.domain.Pageable; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
@RestController | ||
@RequiredArgsConstructor | ||
@RequestMapping("/search-keyword") | ||
public class SearchKeywordController { | ||
|
||
private final SearchKeywordService searchKeywordService; | ||
|
||
@PostMapping("") | ||
public ApiResponse<SearchKeyword> saveKeyword(String keyword) { | ||
|
||
return ApiResponse.onSuccess(searchKeywordService.saveKeyword(keyword)); | ||
} | ||
|
||
@GetMapping("") | ||
public ApiResponse<SearchKeyword> findOne(Long searchKeywordId) { | ||
return ApiResponse.onSuccess(searchKeywordService.findOne(searchKeywordId)); | ||
} | ||
|
||
@GetMapping("/all") | ||
public ApiResponse<Page<SearchKeyword>> findAll(Pageable pageable) { | ||
return ApiResponse.onSuccess(searchKeywordService.findAll(pageable)); | ||
} | ||
|
||
@PutMapping("") | ||
public ApiResponse<SearchKeyword> modifyOne(Long searchKeywordId, String newKeyword) { | ||
return ApiResponse.onSuccess((searchKeywordService.modifyOne(searchKeywordId, newKeyword))); | ||
} | ||
|
||
@DeleteMapping("") | ||
public ApiResponse<String> deleteOne(Long searchKeywordId) { | ||
searchKeywordService.deleteOne(searchKeywordId); | ||
return ApiResponse.onSuccess("OK"); | ||
} | ||
|
||
|
||
|
||
|
||
} |
23 changes: 23 additions & 0 deletions
23
src/main/java/com/bbteam/budgetbuddies/domain/searchkeyword/domain/SearchKeyword.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,23 @@ | ||
package com.bbteam.budgetbuddies.domain.searchkeyword.domain; | ||
|
||
import com.bbteam.budgetbuddies.common.BaseEntity; | ||
import jakarta.persistence.Entity; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Entity | ||
@Getter | ||
@Builder | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
public class SearchKeyword extends BaseEntity { | ||
|
||
private String keyword; | ||
|
||
public void changeKeyword(String newKeyword) { | ||
this.keyword = newKeyword; | ||
} | ||
|
||
} |
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.
해당 API는 키워드를 통해 FAQ를 지우는 메소드인걸까요??
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.
FAQ와 연결된 searchKeyword mapping을 지우는 메소드 입니다!