Skip to content

Commit

Permalink
feat: 검색 조건에 공유 여부 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
peeerr committed Nov 14, 2024
1 parent 4749749 commit 5686e82
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ public ResponseEntity<SuccessResponse<MyDiariesResponse>> getMyDiaries(
@RequestParam(required = false) @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) LocalDate until,
@Parameter(description = "북마크 여부")
@RequestParam(required = false) Boolean bookmark,
@Parameter(description = "공유 여부")
@RequestParam(required = false) Boolean isPublic,
@Parameter(description = "페이지 키")
@RequestParam(defaultValue = "0") int key,
@Parameter(description = "페이지 크기")
Expand All @@ -115,6 +117,7 @@ public ResponseEntity<SuccessResponse<MyDiariesResponse>> getMyDiaries(
.from(from)
.until(until)
.isBookmark(bookmark)
.isPublic(isPublic)
.key(key)
.size(size)
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public class DiaryFilterRequest {
private LocalDate from;
private LocalDate until;
private Boolean isBookmark;
private Boolean isPublic;
private int key;
private int size;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public void createDiaryManual(Long memberId, DiaryManualCreateRequest diaryManua

//카테고리 저장
List<CategoryRequest> categoryRequestList = diaryManualCreateRequest.getCategories();
if(categoryRequestList != null){
if (categoryRequestList != null) {
addDiaryCategory(savedDiary, currentMember.getId(), categoryRequestList);
}
}
Expand All @@ -127,7 +127,7 @@ public MyDiariesResponse getMyDiaries(Long memberId, DiaryFilterRequest diaryFil

Specification<Diary> spec;

if(!diaryFilterRequest.hasFilter()){
if (!diaryFilterRequest.hasFilter()) {
LocalDate today = LocalDate.now();

spec = DiarySpecification.filterDiaries(
Expand All @@ -137,7 +137,8 @@ public MyDiariesResponse getMyDiaries(Long memberId, DiaryFilterRequest diaryFil
today,
diaryFilterRequest.getFrom(),
diaryFilterRequest.getUntil(),
diaryFilterRequest.getIsBookmark())
diaryFilterRequest.getIsBookmark(),
diaryFilterRequest.getIsPublic())
.and((root, query, builder) -> builder.equal(root.get("member"), currentMember));

diaryPage = diaryRepository.findAll(spec,
Expand All @@ -150,7 +151,8 @@ public MyDiariesResponse getMyDiaries(Long memberId, DiaryFilterRequest diaryFil
diaryFilterRequest.getDate(),
diaryFilterRequest.getFrom(),
diaryFilterRequest.getUntil(),
diaryFilterRequest.getIsBookmark())
diaryFilterRequest.getIsBookmark(),
diaryFilterRequest.getIsPublic())
.and((root, query, builder) -> builder.equal(root.get("member"), currentMember));

diaryPage = diaryRepository.findAll(spec,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class DiarySpecification {

public static Specification<Diary> filterDiaries(
String keyword, List<String> emojis, List<String> categories,
LocalDate date, LocalDate from, LocalDate until, Boolean isBookmark) {
LocalDate date, LocalDate from, LocalDate until, Boolean isBookmark, Boolean isPublic) {
return (Root<Diary> root, CriteriaQuery<?> query, CriteriaBuilder builder) -> {
Predicate predicate = builder.conjunction();

Expand All @@ -36,7 +36,7 @@ public static Specification<Diary> filterDiaries(
predicate = builder.and(predicate, categoryJoin.get("categoryName").in(categories));
}

if(date != null){
if (date != null) {
predicate = builder.and(predicate,
builder.or(
builder.and(
Expand Down Expand Up @@ -68,6 +68,10 @@ public static Specification<Diary> filterDiaries(
predicate = builder.and(predicate, builder.equal(root.get("isBookmark"), isBookmark));
}

if (isPublic != null) {
predicate = builder.and(predicate, builder.equal(root.get("isPublic"), isPublic));
}

return predicate;
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ void should_FindDiaries_When_FilteringWithSearchCriteria() {
.locationName("Busan")
.address("Busan Address")
.emoji("😍")
.isPublic(true)
.isPublic(false)
.isBookmark(false)
.build();

Expand All @@ -107,7 +107,8 @@ void should_FindDiaries_When_FilteringWithSearchCriteria() {
null, // date
null, // from
null, // until
false // isBookmark
false, // isBookmark
true // isPublic
);

Page<Diary> result = diaryRepository.findAll(spec, PageRequest.of(0, 10));
Expand All @@ -132,7 +133,7 @@ void should_FindDiaries_When_FilteringBookmarked() {
.locationName("Seoul")
.address("Seoul Address")
.isBookmark(true)
.isPublic(false)
.isPublic(true)
.build();

Diary diary2 = createDiary(member, "Content 2", "Busan", "Busan Address");
Expand All @@ -156,7 +157,8 @@ void should_FindDiaries_When_FilteringBookmarked() {
null, // date
null, // from
null, // until
true // isBookmark
true, // isBookmark
true // isPublic
);

Page<Diary> result = diaryRepository.findAll(spec, PageRequest.of(0, 10));
Expand Down

0 comments on commit 5686e82

Please sign in to comment.