From 5686e828d26117cb7b3a50f4078c7304d4436a52 Mon Sep 17 00:00:00 2001 From: JunHyeongChoi Date: Thu, 14 Nov 2024 21:56:37 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=EA=B2=80=EC=83=89=20=EC=A1=B0=EA=B1=B4?= =?UTF-8?q?=EC=97=90=20=EA=B3=B5=EC=9C=A0=20=EC=97=AC=EB=B6=80=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../everymoment/controller/DiaryController.java | 3 +++ .../everymoment/dto/request/DiaryFilterRequest.java | 1 + .../potatocake/everymoment/service/DiaryService.java | 10 ++++++---- .../everymoment/service/DiarySpecification.java | 8 ++++++-- .../everymoment/repository/DiaryRepositoryTest.java | 10 ++++++---- 5 files changed, 22 insertions(+), 10 deletions(-) diff --git a/src/main/java/com/potatocake/everymoment/controller/DiaryController.java b/src/main/java/com/potatocake/everymoment/controller/DiaryController.java index 41579ac..afae616 100644 --- a/src/main/java/com/potatocake/everymoment/controller/DiaryController.java +++ b/src/main/java/com/potatocake/everymoment/controller/DiaryController.java @@ -100,6 +100,8 @@ public ResponseEntity> 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 = "페이지 크기") @@ -115,6 +117,7 @@ public ResponseEntity> getMyDiaries( .from(from) .until(until) .isBookmark(bookmark) + .isPublic(isPublic) .key(key) .size(size) .build(); diff --git a/src/main/java/com/potatocake/everymoment/dto/request/DiaryFilterRequest.java b/src/main/java/com/potatocake/everymoment/dto/request/DiaryFilterRequest.java index 29fbb5d..429f0c7 100644 --- a/src/main/java/com/potatocake/everymoment/dto/request/DiaryFilterRequest.java +++ b/src/main/java/com/potatocake/everymoment/dto/request/DiaryFilterRequest.java @@ -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; diff --git a/src/main/java/com/potatocake/everymoment/service/DiaryService.java b/src/main/java/com/potatocake/everymoment/service/DiaryService.java index 1bdc4e9..da0c65d 100644 --- a/src/main/java/com/potatocake/everymoment/service/DiaryService.java +++ b/src/main/java/com/potatocake/everymoment/service/DiaryService.java @@ -108,7 +108,7 @@ public void createDiaryManual(Long memberId, DiaryManualCreateRequest diaryManua //카테고리 저장 List categoryRequestList = diaryManualCreateRequest.getCategories(); - if(categoryRequestList != null){ + if (categoryRequestList != null) { addDiaryCategory(savedDiary, currentMember.getId(), categoryRequestList); } } @@ -127,7 +127,7 @@ public MyDiariesResponse getMyDiaries(Long memberId, DiaryFilterRequest diaryFil Specification spec; - if(!diaryFilterRequest.hasFilter()){ + if (!diaryFilterRequest.hasFilter()) { LocalDate today = LocalDate.now(); spec = DiarySpecification.filterDiaries( @@ -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, @@ -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, diff --git a/src/main/java/com/potatocake/everymoment/service/DiarySpecification.java b/src/main/java/com/potatocake/everymoment/service/DiarySpecification.java index 7eefe26..01184f3 100644 --- a/src/main/java/com/potatocake/everymoment/service/DiarySpecification.java +++ b/src/main/java/com/potatocake/everymoment/service/DiarySpecification.java @@ -18,7 +18,7 @@ public class DiarySpecification { public static Specification filterDiaries( String keyword, List emojis, List categories, - LocalDate date, LocalDate from, LocalDate until, Boolean isBookmark) { + LocalDate date, LocalDate from, LocalDate until, Boolean isBookmark, Boolean isPublic) { return (Root root, CriteriaQuery query, CriteriaBuilder builder) -> { Predicate predicate = builder.conjunction(); @@ -36,7 +36,7 @@ public static Specification filterDiaries( predicate = builder.and(predicate, categoryJoin.get("categoryName").in(categories)); } - if(date != null){ + if (date != null) { predicate = builder.and(predicate, builder.or( builder.and( @@ -68,6 +68,10 @@ public static Specification 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; }; } diff --git a/src/test/java/com/potatocake/everymoment/repository/DiaryRepositoryTest.java b/src/test/java/com/potatocake/everymoment/repository/DiaryRepositoryTest.java index 74f276c..37ec8df 100644 --- a/src/test/java/com/potatocake/everymoment/repository/DiaryRepositoryTest.java +++ b/src/test/java/com/potatocake/everymoment/repository/DiaryRepositoryTest.java @@ -93,7 +93,7 @@ void should_FindDiaries_When_FilteringWithSearchCriteria() { .locationName("Busan") .address("Busan Address") .emoji("😍") - .isPublic(true) + .isPublic(false) .isBookmark(false) .build(); @@ -107,7 +107,8 @@ void should_FindDiaries_When_FilteringWithSearchCriteria() { null, // date null, // from null, // until - false // isBookmark + false, // isBookmark + true // isPublic ); Page result = diaryRepository.findAll(spec, PageRequest.of(0, 10)); @@ -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"); @@ -156,7 +157,8 @@ void should_FindDiaries_When_FilteringBookmarked() { null, // date null, // from null, // until - true // isBookmark + true, // isBookmark + true // isPublic ); Page result = diaryRepository.findAll(spec, PageRequest.of(0, 10));