From fe12a4ec3c85c3055b6ee3f3e0757bc1d602a048 Mon Sep 17 00:00:00 2001 From: seungryeol Date: Wed, 31 Jul 2024 12:39:18 +0900 Subject: [PATCH 1/4] =?UTF-8?q?[fix]=20=EC=B1=84=EC=86=8C=EC=9D=98=20?= =?UTF-8?q?=EC=9D=BC=EA=B8=B0=20=EC=A1=B0=ED=9A=8C=20=EC=8B=9C=20=EC=A1=B0?= =?UTF-8?q?=ED=9A=8C=20=EB=8D=B0=EC=9D=B4=ED=84=B0=20=EC=B6=94=EA=B0=80=20?= =?UTF-8?q?(likeCount,commentCount,=20myLike=20)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/MyVeggieDiaryController.java | 9 +++---- .../domain/myveggiegarden/dto/DiaryAll.java | 21 +++++++++++++++ .../myveggiegarden/dto/response/AllDairy.java | 26 +++++++++++++------ .../repository/DiaryRepository.java | 12 +++++++++ .../service/MyVeggieDiaryService.java | 13 +++++----- 5 files changed, 62 insertions(+), 19 deletions(-) create mode 100644 src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/dto/DiaryAll.java diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/controller/MyVeggieDiaryController.java b/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/controller/MyVeggieDiaryController.java index 403a9d69..5904b1b8 100644 --- a/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/controller/MyVeggieDiaryController.java +++ b/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/controller/MyVeggieDiaryController.java @@ -70,9 +70,7 @@ public BaseResponseDto selectDiaryOne( } @GetMapping(value = "/{myVeggieId}/count") - public BaseResponseDto selectDiaryCount( - @PathVariable("myVeggieId") Long myVeggieId - ) { + public BaseResponseDto selectDiaryCount(@PathVariable("myVeggieId") Long myVeggieId) { MyVeggie myVeggie = MyVeggie.builder().id(myVeggieId).build(); MyVeggieDiaryCount result = myVeggieDiaryService.selectDiaryCount(myVeggie); @@ -81,10 +79,11 @@ public BaseResponseDto selectDiaryCount( @GetMapping(value = "/{myVeggieId}/all") public BaseResponseDto selectDiaryAll( - @PathVariable("myVeggieId") Long myVeggieId + @PathVariable("myVeggieId") Long myVeggieId, + @AuthenticationPrincipal CustomUser user ) { MyVeggie myVeggie = MyVeggie.builder().id(myVeggieId).build(); - List result = myVeggieDiaryService.selectDiaryAll(myVeggie); + List result = myVeggieDiaryService.selectDiaryAll(myVeggie, user.getUserId()); return BaseResponseDto.of(SuccessCode.SUCCESS, result); } diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/dto/DiaryAll.java b/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/dto/DiaryAll.java new file mode 100644 index 00000000..ea70ef1b --- /dev/null +++ b/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/dto/DiaryAll.java @@ -0,0 +1,21 @@ +package com.modernfarmer.farmusspring.domain.myveggiegarden.dto; + +import com.modernfarmer.farmusspring.domain.myveggiegarden.entity.Diary; +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.RequiredArgsConstructor; + +@NoArgsConstructor +@Getter +public class DiaryAll { + + private Diary diary; + private boolean myLike; + + public DiaryAll(Diary diary, boolean myLike) { + this.diary = diary; + this.myLike = myLike; + } + +} diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/dto/response/AllDairy.java b/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/dto/response/AllDairy.java index ef5b3fc6..6b9ad2a8 100644 --- a/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/dto/response/AllDairy.java +++ b/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/dto/response/AllDairy.java @@ -1,5 +1,6 @@ package com.modernfarmer.farmusspring.domain.myveggiegarden.dto.response; +import com.modernfarmer.farmusspring.domain.myveggiegarden.dto.DiaryAll; import com.modernfarmer.farmusspring.domain.myveggiegarden.entity.Diary; import lombok.AllArgsConstructor; import lombok.Getter; @@ -18,20 +19,29 @@ public class AllDairy { private String content; private Boolean isOpen; private String state; + private Long diaryId; + private int likeCount; + private int commentCount; + private boolean myLike; - public static AllDairy of(Diary diary, String date){ + public static AllDairy of(DiaryAll diaryAll, String date){ return new AllDairy( date, - diary.getImage(), - diary.getContent(), - diary.getIsOpen(), - diary.getState() + diaryAll.getDiary().getImage(), + diaryAll.getDiary().getContent(), + diaryAll.getDiary().getIsOpen(), + diaryAll.getDiary().getState(), + diaryAll.getDiary().getId(), + diaryAll.getDiary().getDiaryComments().size(), + diaryAll.getDiary().getDiaryLikes().size(), + diaryAll.isMyLike() + ); } - public static List processData(List diaryList){ - return diaryList.stream() - .map(diary -> AllDairy.of(diary, formatDate(diary.getCreatedDate()))) + public static List processData(List diaryAllList){ + return diaryAllList.stream() + .map(diaryAll -> AllDairy.of(diaryAll, formatDate(diaryAll.getDiary().getCreatedDate()))) .toList(); } diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/repository/DiaryRepository.java b/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/repository/DiaryRepository.java index 6b43cfd6..11c87b9b 100644 --- a/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/repository/DiaryRepository.java +++ b/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/repository/DiaryRepository.java @@ -1,6 +1,8 @@ package com.modernfarmer.farmusspring.domain.myveggiegarden.repository; import com.modernfarmer.farmusspring.domain.farmclub.entity.FarmClub; +import com.modernfarmer.farmusspring.domain.myveggiegarden.dto.DiaryAll; +import com.modernfarmer.farmusspring.domain.myveggiegarden.dto.response.AllDairy; import com.modernfarmer.farmusspring.domain.myveggiegarden.entity.Diary; import com.modernfarmer.farmusspring.domain.myveggiegarden.entity.DiaryComment; import com.modernfarmer.farmusspring.domain.myveggiegarden.entity.DiaryLike; @@ -46,4 +48,14 @@ public interface DiaryRepository extends JpaRepository { ) List findDiaryByFarmClub(@Param("farmClubId") Long farmClubId); + @Query("SELECT new com.modernfarmer.farmusspring.domain.myveggiegarden.dto.DiaryAll(d, " + + "CASE WHEN dl.user.id = :userId THEN true ELSE false END) " + + "FROM diary AS d " + + "JOIN FETCH d.myVeggie AS mv " + + "JOIN FETCH mv.user " + + "LEFT JOIN diary_like AS dl ON dl.diary.id = d.id AND dl.user.id = :userId " + + "WHERE d.myVeggie = :myVeggie " + + "ORDER BY d.createdDate DESC") + List findDiariesByMyVeggie(@Param("myVeggie") MyVeggie myVeggie, @Param("userId") Long userId); + } diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/service/MyVeggieDiaryService.java b/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/service/MyVeggieDiaryService.java index e34426c9..edf36764 100644 --- a/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/service/MyVeggieDiaryService.java +++ b/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/service/MyVeggieDiaryService.java @@ -1,6 +1,7 @@ package com.modernfarmer.farmusspring.domain.myveggiegarden.service; import com.modernfarmer.farmusspring.domain.farmclub.entity.FarmClub; +import com.modernfarmer.farmusspring.domain.myveggiegarden.dto.DiaryAll; import com.modernfarmer.farmusspring.domain.myveggiegarden.dto.response.*; import com.modernfarmer.farmusspring.domain.myveggiegarden.entity.Diary; import com.modernfarmer.farmusspring.domain.myveggiegarden.entity.DiaryComment; @@ -89,20 +90,20 @@ private List proccessFarmClubData(List diaryList){ );}).toList(); } + @Transactional + public List selectDiaryAll(MyVeggie myVeggie, Long userId) { + List diaryList = diaryRepository.findDiariesByMyVeggie(myVeggie, userId); + return AllDairy.processData(diaryList); + } + @Transactional public MyVeggieDiaryCount selectDiaryCount(MyVeggie myVeggie) { - List diaryList = myVeggieRepository.findDiariesByMyVeggie(myVeggie); return MyVeggieDiaryCount.processData(diaryList); } - @Transactional - public List selectDiaryAll(MyVeggie myVeggie) { - List diaryList = selectDiaryByMyVeggie(myVeggie); - return AllDairy.processData(diaryList); - } @Transactional From 2cc23fd7aeaee866544eb3e2044efb07e87e1a92 Mon Sep 17 00:00:00 2001 From: seungryeol Date: Wed, 31 Jul 2024 13:11:00 +0900 Subject: [PATCH 2/4] =?UTF-8?q?[fix]=20=ED=8C=9C=ED=81=B4=EB=9F=BD?= =?UTF-8?q?=EB=B3=84=20=EC=B1=84=EC=86=8C=20=EC=9D=BC=EA=B8=B0(state,=20my?= =?UTF-8?q?Like=20)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/MyVeggieDiaryController.java | 5 ++--- .../dto/response/FarmClubDiary.java | 8 ++++++-- .../repository/DiaryRepository.java | 6 ++++-- .../service/MyVeggieDiaryService.java | 20 ++++++++++--------- 4 files changed, 23 insertions(+), 16 deletions(-) diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/controller/MyVeggieDiaryController.java b/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/controller/MyVeggieDiaryController.java index 5904b1b8..020132f4 100644 --- a/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/controller/MyVeggieDiaryController.java +++ b/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/controller/MyVeggieDiaryController.java @@ -46,10 +46,9 @@ public BaseResponseDto settingMyVeggieDiary( @GetMapping(value = "/{farmClubId}") - public BaseResponseDto findFarmClubDiary( - @PathVariable("farmClubId") Long farmClubId){ + public BaseResponseDto findFarmClubDiary(@PathVariable("farmClubId") Long farmClubId, @AuthenticationPrincipal CustomUser user){ - List farmClubDiaryList = myVeggieDiaryService.findDiaryAccordingToFarmClub(farmClubId); + List farmClubDiaryList = myVeggieDiaryService.findDiaryAccordingToFarmClub(farmClubId, user.getUserId()); return BaseResponseDto.of(SuccessCode.SUCCESS, farmClubDiaryList); } diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/dto/response/FarmClubDiary.java b/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/dto/response/FarmClubDiary.java index eee71f42..caaaac7d 100644 --- a/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/dto/response/FarmClubDiary.java +++ b/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/dto/response/FarmClubDiary.java @@ -20,8 +20,10 @@ public class FarmClubDiary { private int commentCount; private String nickname; private String profileImage; + private boolean myLike; + private String state; - public static FarmClubDiary of(Diary diary, User user, String writeDateTime, int likeCount, int commentCount){ + public static FarmClubDiary of(Diary diary, User user, String writeDateTime, int likeCount, int commentCount, boolean myLike, String status){ return new FarmClubDiary( diary.getId(), diary.getImage(), @@ -30,7 +32,9 @@ public static FarmClubDiary of(Diary diary, User user, String writeDateTime, int likeCount, commentCount, user.getNickname(), - user.getProfileImage() + user.getProfileImage(), + myLike, + status ); } diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/repository/DiaryRepository.java b/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/repository/DiaryRepository.java index 11c87b9b..7dffbd64 100644 --- a/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/repository/DiaryRepository.java +++ b/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/repository/DiaryRepository.java @@ -39,14 +39,16 @@ public interface DiaryRepository extends JpaRepository { List findDiary(@Param("diaryId") Long diaryId, @Param("farmClubId") Long farmClubId); - @Query("SELECT d FROM diary AS d " + + @Query("SELECT new com.modernfarmer.farmusspring.domain.myveggiegarden.dto.DiaryAll(d, " + + "CASE WHEN dl.user.id = :userId THEN true ELSE false END) " + + "FROM diary AS d " + "JOIN FETCH d.myVeggie AS mv " + "JOIN FETCH mv.user " + "LEFT JOIN diary_comment AS dc ON dc.id = d.id "+ "LEFT JOIN diary_like AS dl ON dl.id = d.id " + "WHERE d.farmClub.id = :farmClubId AND d.isOpen = true " ) - List findDiaryByFarmClub(@Param("farmClubId") Long farmClubId); + List findDiaryByFarmClub(@Param("farmClubId") Long farmClubId, @Param("userId") Long userId); @Query("SELECT new com.modernfarmer.farmusspring.domain.myveggiegarden.dto.DiaryAll(d, " + "CASE WHEN dl.user.id = :userId THEN true ELSE false END) " + diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/service/MyVeggieDiaryService.java b/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/service/MyVeggieDiaryService.java index edf36764..e8b219e0 100644 --- a/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/service/MyVeggieDiaryService.java +++ b/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/service/MyVeggieDiaryService.java @@ -72,21 +72,23 @@ public BaseResponseDto checkTodayDiary( @Transactional - public List findDiaryAccordingToFarmClub(Long farmClubId) { - List diaryList = diaryRepository.findDiaryByFarmClub(farmClubId); + public List findDiaryAccordingToFarmClub(Long farmClubId, Long userId) { + List diaryList = diaryRepository.findDiaryByFarmClub(farmClubId, userId); List proccessData = proccessFarmClubData(diaryList); return proccessData; } - private List proccessFarmClubData(List diaryList){ - return diaryList.stream().map(diary -> { - User user = diary.getMyVeggie().getUser(); + private List proccessFarmClubData(List diaryAllList){ + return diaryAllList.stream().map(allDiary -> { + User user = allDiary.getDiary().getMyVeggie().getUser(); return FarmClubDiary.of( - diary, + allDiary.getDiary(), user, - DateManager.dotDateTime(diary.getCreatedDate()), - diary.getDiaryComments().size(), - diary.getDiaryLikes().size() + DateManager.dotDateTime(allDiary.getDiary().getCreatedDate()), + allDiary.getDiary().getDiaryComments().size(), + allDiary.getDiary().getDiaryLikes().size(), + allDiary.isMyLike(), + allDiary.getDiary().getState() );}).toList(); } From 6b5af754e63877ab532b9ea1aadbbf12263b55af Mon Sep 17 00:00:00 2001 From: seungryeol Date: Thu, 1 Aug 2024 16:35:28 +0900 Subject: [PATCH 3/4] =?UTF-8?q?[fix]=20=EB=93=A4=EC=97=AC=EC=93=B0?= =?UTF-8?q?=EA=B8=B0=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/MyVeggieDiaryController.java | 8 ++---- .../repository/DiaryRepository.java | 13 ++++----- .../service/MyVeggieDiaryService.java | 27 +++++-------------- 3 files changed, 13 insertions(+), 35 deletions(-) diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/controller/MyVeggieDiaryController.java b/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/controller/MyVeggieDiaryController.java index 463e5703..747e0db6 100644 --- a/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/controller/MyVeggieDiaryController.java +++ b/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/controller/MyVeggieDiaryController.java @@ -30,7 +30,7 @@ public class MyVeggieDiaryController { private final MyVeggieDiaryService myVeggieDiaryService; - @PostMapping(value = "", produces = MediaType.APPLICATION_JSON_VALUE) + @PostMapping(produces = MediaType.APPLICATION_JSON_VALUE) public BaseResponseDto settingMyVeggieDiary( @RequestPart(value = "image", required = false) MultipartFile multipartFile, @RequestPart MyVeggieDiaryInsert myVeggieDiaryInsert @@ -47,7 +47,6 @@ public BaseResponseDto settingMyVeggieDiary( @GetMapping(value = "/{farmClubId}") public BaseResponseDto findFarmClubDiary(@PathVariable("farmClubId") Long farmClubId, @AuthenticationPrincipal CustomUser user){ - List farmClubDiaryList = myVeggieDiaryService.findDiaryAccordingToFarmClub(farmClubId, user.getUserId()); return BaseResponseDto.of(SuccessCode.SUCCESS, farmClubDiaryList); } @@ -55,9 +54,7 @@ public BaseResponseDto findFarmClubDiary(@PathVariable("farmClubI @GetMapping(value = "/{myVeggieId}/check") - public BaseResponseDto checkTodayDiary( - @PathVariable("myVeggieId") Long myVeggieId - ) { + public BaseResponseDto checkTodayDiary(@PathVariable("myVeggieId") Long myVeggieId) { return myVeggieDiaryService.checkTodayDiary(MyVeggie.builder().id(myVeggieId).build()); } @@ -70,7 +67,6 @@ public BaseResponseDto selectDiaryOne(@PathVariable("myV public BaseResponseDto selectDiaryCount(@PathVariable("myVeggieId") Long myVeggieId) { MyVeggie myVeggie = MyVeggie.builder().id(myVeggieId).build(); MyVeggieDiaryCount result = myVeggieDiaryService.selectDiaryCount(myVeggie); - return BaseResponseDto.of(SuccessCode.SUCCESS, result); } diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/repository/DiaryRepository.java b/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/repository/DiaryRepository.java index b9dfa010..096af0fd 100644 --- a/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/repository/DiaryRepository.java +++ b/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/repository/DiaryRepository.java @@ -1,8 +1,6 @@ package com.modernfarmer.farmusspring.domain.myveggiegarden.repository; -import com.modernfarmer.farmusspring.domain.farmclub.entity.FarmClub; -import com.modernfarmer.farmusspring.domain.myveggiegarden.dto.DiaryAll; -import com.modernfarmer.farmusspring.domain.myveggiegarden.dto.response.AllDairy; +import com.modernfarmer.farmusspring.domain.myveggiegarden.dto.SortedMyLikeDiary; import com.modernfarmer.farmusspring.domain.myveggiegarden.entity.Diary; import com.modernfarmer.farmusspring.domain.myveggiegarden.entity.DiaryComment; import com.modernfarmer.farmusspring.domain.myveggiegarden.entity.DiaryLike; @@ -15,7 +13,6 @@ import org.springframework.stereotype.Repository; import java.util.List; -import java.util.Optional; @Repository @@ -38,7 +35,7 @@ public interface DiaryRepository extends JpaRepository { List findDiaryById(@Param("diaryId") Long diaryId); - @Query("SELECT new com.modernfarmer.farmusspring.domain.myveggiegarden.dto.DiaryAll(d, " + + @Query("SELECT new com.modernfarmer.farmusspring.domain.myveggiegarden.dto.SortedMyLikeDiary(d, " + "CASE WHEN dl.user.id = :userId THEN true ELSE false END) " + "FROM diary AS d " + "JOIN FETCH d.myVeggie AS mv " + @@ -47,9 +44,9 @@ public interface DiaryRepository extends JpaRepository { "LEFT JOIN diary_like AS dl ON dl.id = d.id " + "WHERE d.farmClub.id = :farmClubId AND d.isOpen = true " ) - List findDiaryByFarmClub(@Param("farmClubId") Long farmClubId, @Param("userId") Long userId); + List findDiaryByFarmClub(@Param("farmClubId") Long farmClubId, @Param("userId") Long userId); - @Query("SELECT new com.modernfarmer.farmusspring.domain.myveggiegarden.dto.DiaryAll(d, " + + @Query("SELECT new com.modernfarmer.farmusspring.domain.myveggiegarden.dto.SortedMyLikeDiary(d, " + "CASE WHEN dl.user.id = :userId THEN true ELSE false END) " + "FROM diary AS d " + "JOIN FETCH d.myVeggie AS mv " + @@ -57,7 +54,7 @@ public interface DiaryRepository extends JpaRepository { "LEFT JOIN diary_like AS dl ON dl.diary.id = d.id AND dl.user.id = :userId " + "WHERE d.myVeggie = :myVeggie " + "ORDER BY d.createdDate DESC") - List findDiariesByMyVeggie(@Param("myVeggie") MyVeggie myVeggie, @Param("userId") Long userId); + List findDiariesByMyVeggie(@Param("myVeggie") MyVeggie myVeggie, @Param("userId") Long userId); @Query("SELECT d FROM diary AS d WHERE d.myVeggie = :myVeggie AND FUNCTION('DATE', d.createdDate) = CURRENT_DATE") List findDiaryByToday(@Param("myVeggie") MyVeggie myVeggie); diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/service/MyVeggieDiaryService.java b/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/service/MyVeggieDiaryService.java index 0572d93f..932a3982 100644 --- a/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/service/MyVeggieDiaryService.java +++ b/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/service/MyVeggieDiaryService.java @@ -1,7 +1,6 @@ package com.modernfarmer.farmusspring.domain.myveggiegarden.service; -import com.modernfarmer.farmusspring.domain.farmclub.entity.FarmClub; -import com.modernfarmer.farmusspring.domain.myveggiegarden.dto.DiaryAll; +import com.modernfarmer.farmusspring.domain.myveggiegarden.dto.SortedMyLikeDiary; import com.modernfarmer.farmusspring.domain.myveggiegarden.dto.response.*; import com.modernfarmer.farmusspring.domain.myveggiegarden.entity.Diary; import com.modernfarmer.farmusspring.domain.myveggiegarden.entity.DiaryComment; @@ -22,7 +21,6 @@ import org.springframework.transaction.annotation.Transactional; import org.springframework.web.multipart.MultipartFile; import java.io.IOException; -import java.time.format.DateTimeFormatter; import java.util.List; import java.util.Optional; @@ -46,7 +44,6 @@ public BaseResponseDto settingMyVeggieDiary( String state, Long myVeggieId ) throws IOException { - String imageUrl = getImageUrl(multipartFile); addMyyVeggieDiary( content, @@ -60,10 +57,7 @@ public BaseResponseDto settingMyVeggieDiary( @Transactional - public BaseResponseDto checkTodayDiary( - MyVeggie myVeggie - ) { - + public BaseResponseDto checkTodayDiary(MyVeggie myVeggie) { Diary diary = selectTodayDiary(myVeggie); boolean state = verifyDiaryState(diary); return BaseResponseDto.of(SuccessCode.SUCCESS,CheckTodayDiaryResponse.of(state)); @@ -73,12 +67,12 @@ public BaseResponseDto checkTodayDiary( @Transactional public List findDiaryAccordingToFarmClub(Long farmClubId, Long userId) { - List diaryList = diaryRepository.findDiaryByFarmClub(farmClubId, userId); + List diaryList = diaryRepository.findDiaryByFarmClub(farmClubId, userId); List proccessData = proccessFarmClubData(diaryList); return proccessData; } - private List proccessFarmClubData(List diaryAllList){ + private List proccessFarmClubData(List diaryAllList){ return diaryAllList.stream().map(allDiary -> { User user = allDiary.getDiary().getMyVeggie().getUser(); return FarmClubDiary.of( @@ -94,20 +88,16 @@ private List proccessFarmClubData(List diaryAllList){ @Transactional public List selectDiaryAll(MyVeggie myVeggie, Long userId) { - List diaryList = diaryRepository.findDiariesByMyVeggie(myVeggie, userId); + List diaryList = diaryRepository.findDiariesByMyVeggie(myVeggie, userId); return AllDairy.processData(diaryList); } - @Transactional public MyVeggieDiaryCount selectDiaryCount(MyVeggie myVeggie) { List diaryList = myVeggieRepository.findDiariesByMyVeggie(myVeggie); return MyVeggieDiaryCount.processData(diaryList); } - - - @Transactional public void pressLike(Long userId, Long diaryId) { User userData = userService.selectUserById(userId); @@ -182,14 +172,10 @@ public void deleteLike(User user, Diary diary){ } public boolean verifyDiaryState(Diary diary){ - - if(diary == null){ - return true; - } + if(diary == null){return true;} return false; } - public Diary selectTodayDiary(MyVeggie myVeggie){ return myVeggieRepository.findDiariesByMyVeggieAndToday(myVeggie); } @@ -221,7 +207,6 @@ public void validateDiaryComment(Optional diaryComment){ } } - private void addMyyVeggieDiary( String content, boolean isOpen, From 8919a2952c57f2d79bec86be3e7e0643f5b1f75c Mon Sep 17 00:00:00 2001 From: seungryeol Date: Thu, 1 Aug 2024 16:35:39 +0900 Subject: [PATCH 4/4] =?UTF-8?q?[fix]=20dto=EB=AA=85=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dto/{DiaryAll.java => SortedMyLikeDiary.java} | 6 ++---- .../domain/myveggiegarden/dto/response/AllDairy.java | 7 +++---- 2 files changed, 5 insertions(+), 8 deletions(-) rename src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/dto/{DiaryAll.java => SortedMyLikeDiary.java} (69%) diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/dto/DiaryAll.java b/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/dto/SortedMyLikeDiary.java similarity index 69% rename from src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/dto/DiaryAll.java rename to src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/dto/SortedMyLikeDiary.java index ea70ef1b..5db9953a 100644 --- a/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/dto/DiaryAll.java +++ b/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/dto/SortedMyLikeDiary.java @@ -1,19 +1,17 @@ package com.modernfarmer.farmusspring.domain.myveggiegarden.dto; import com.modernfarmer.farmusspring.domain.myveggiegarden.entity.Diary; -import lombok.AllArgsConstructor; import lombok.Getter; import lombok.NoArgsConstructor; -import lombok.RequiredArgsConstructor; @NoArgsConstructor @Getter -public class DiaryAll { +public class SortedMyLikeDiary { private Diary diary; private boolean myLike; - public DiaryAll(Diary diary, boolean myLike) { + public SortedMyLikeDiary(Diary diary, boolean myLike) { this.diary = diary; this.myLike = myLike; } diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/dto/response/AllDairy.java b/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/dto/response/AllDairy.java index 6b9ad2a8..b1ce6793 100644 --- a/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/dto/response/AllDairy.java +++ b/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/dto/response/AllDairy.java @@ -1,7 +1,6 @@ package com.modernfarmer.farmusspring.domain.myveggiegarden.dto.response; -import com.modernfarmer.farmusspring.domain.myveggiegarden.dto.DiaryAll; -import com.modernfarmer.farmusspring.domain.myveggiegarden.entity.Diary; +import com.modernfarmer.farmusspring.domain.myveggiegarden.dto.SortedMyLikeDiary; import lombok.AllArgsConstructor; import lombok.Getter; import lombok.NoArgsConstructor; @@ -24,7 +23,7 @@ public class AllDairy { private int commentCount; private boolean myLike; - public static AllDairy of(DiaryAll diaryAll, String date){ + public static AllDairy of(SortedMyLikeDiary diaryAll, String date){ return new AllDairy( date, diaryAll.getDiary().getImage(), @@ -39,7 +38,7 @@ public static AllDairy of(DiaryAll diaryAll, String date){ ); } - public static List processData(List diaryAllList){ + public static List processData(List diaryAllList){ return diaryAllList.stream() .map(diaryAll -> AllDairy.of(diaryAll, formatDate(diaryAll.getDiary().getCreatedDate()))) .toList();