-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
[feat] FAQ 검색기능 추가
- Loading branch information
Showing
18 changed files
with
479 additions
and
5 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
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.