diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/dto/response/DiaryInteractionsDto.java b/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/dto/response/DiaryInteractionsDto.java index 4085406..a753c5e 100644 --- a/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/dto/response/DiaryInteractionsDto.java +++ b/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/dto/response/DiaryInteractionsDto.java @@ -18,12 +18,14 @@ public class DiaryInteractionsDto { private List diaryCommentContent; private int likeCount; private int commentCount; + private boolean myLike; - public static DiaryInteractionsDto of(List diaryCommentContentList, int likeCount, int commentCount){ + public static DiaryInteractionsDto of(List diaryCommentContentList, int likeCount, int commentCount, boolean myLike){ return new DiaryInteractionsDto( diaryCommentContentList, likeCount, - commentCount + commentCount, + myLike ); } } 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 df54365..aef0ee0 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 @@ -63,14 +63,12 @@ public BaseResponseDto settingMyVeggieDiary( ); return BaseResponseDto.of(SuccessCode.SUCCESS,null); } - @Transactional public BaseResponseDto checkTodayDiary(MyVeggie myVeggie) { Diary diary = selectTodayDiary(myVeggie); boolean state = verifyDiaryState(diary); return BaseResponseDto.of(SuccessCode.SUCCESS,CheckTodayDiaryResponse.of(state)); } - @Transactional public void eraseDiary(DiaryDeleteDto diaryDeleteDto, Long userId){ Optional myVeggie = myVeggieRepository.findMyVeggieByIdAndUserId((diaryDeleteDto.getMyVeggieId()), userId); @@ -80,19 +78,16 @@ public void eraseDiary(DiaryDeleteDto diaryDeleteDto, Long userId){ validateDiaryDelete(diary, diaryDeleteDto.getDiaryId()); diaryRepository.deleteDiaryById(diaryDeleteDto.getDiaryId()); } - public void verifyDiary(Optional diary){ if(diary.isEmpty()){ throw new DiaryNotFoundException("해당 일기는 존재하지 않습니다.", MyVeggieGardenErrorCode.NOT_FOUND_DIARY); } } - public void validateDiaryDelete(Optional diary, Long diaryId){ if(!diary.get().getId().equals(diaryId)){ throw new DiaryAccessDeniedException("해당 일기 접근권한이 없습니다.", MyVeggieGardenErrorCode.NO_ACCESS_DIARY); } } - public void verifyMyVeggie(Optional myVeggie){ if(myVeggie.isEmpty()){ throw new MyVeggieNotFoundException("존재하지 않는 채소입니다.",MyVeggieGardenErrorCode.NOT_FOUND_VEGGIE); @@ -104,7 +99,6 @@ public List findDiaryAccordingToFarmClub(Long farmClubId, Long us List proccessData = proccessFarmClubData(diaryList); return proccessData; } - private List proccessFarmClubData(List diaryAllList){ return diaryAllList.stream().map(allDiary -> { User user = allDiary.getDiary().getMyVeggie().getUser(); @@ -118,19 +112,16 @@ private List proccessFarmClubData(List diaryAl allDiary.getDiary().getState() );}).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 void pressLike(Long userId, Long diaryId) { Optional diaryLike = diaryLikeRepository.findDiaryLikeByDiaryIdAndUserId(diaryId, userId); @@ -139,34 +130,29 @@ public void pressLike(Long userId, Long diaryId) { Diary diaryData = selectDiaryById(diaryId); insertLike(userData, diaryData); } - public void checkLikeData(Optional diaryLike){ if(diaryLike.isPresent()) { throw new LikeAlreadyExistExcpetion("좋아요 권한 에러", MyVeggieGardenErrorCode.EXIST_ALREADY_LIKE); } } - @Transactional public void cancelLike(User user, Diary diary) { DiaryLike diaryLike = diaryRepository.findDiaryLikeByIdAndUser(user, diary); checkLikeDeleteData(diaryLike); deleteLike(user, diary); } - @Transactional public void writeComment(Long userId, Long diaryId, String content) { User userData = userService.selectUserById(userId); Diary diaryData = selectDiaryById(diaryId); insertComment(content, userData, diaryData); } - @Transactional public void deleteComment(User user, Long diaryCommentId) { Optional diaryCommentData = myVeggieRepository.findDiaryCommentByIdAndUserId(diaryCommentId, user); validateDiaryComment(diaryCommentData); myVeggieRepository.deleteDiaryCommentByIdAndUserId(diaryCommentId, user); } - @Transactional public void updateComment(User user, Long diaryCommentId, String content) { Optional diaryCommentData = myVeggieRepository.findDiaryCommentByIdAndUserId(diaryCommentId, user); @@ -186,15 +172,14 @@ public BaseResponseDto selectDiaryOne(MyVeggie myVeggie) DateManager.formatDate(diaryList.get(0).getCreatedDate()) )); } - - @Transactional public DiaryInteractionsDto selectComment(Long userId, Long diaryId) { List diaryCommentList = diaryRepository.findDiaryById(diaryId); List diaryCommentContent = DiaryCommentContent.processData(diaryCommentList, userId); int likeCount = diaryLikeRepository.findDiaryLikeCountById(diaryId); int commentCount = diaryCommentRepository.findDiaryCommentCountById(diaryId); - return DiaryInteractionsDto.of(diaryCommentContent,likeCount,commentCount); + Optional diaryLike = diaryLikeRepository.findDiaryLikeByDiaryIdAndUserId(diaryId, userId); + return DiaryInteractionsDto.of(diaryCommentContent,likeCount,commentCount, diaryLike.isPresent()); } public void insertComment(String content, User user, Diary diary){ DiaryComment diaryComment = DiaryComment.createDiaryComment(content, diary, user);