Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[fix] 댓글 조회 myLike 데이터 추가 #84

Merged
merged 2 commits into from
Aug 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,14 @@ public class DiaryInteractionsDto {
private List<DiaryCommentContent> diaryCommentContent;
private int likeCount;
private int commentCount;
private boolean myLike;

public static DiaryInteractionsDto of(List<DiaryCommentContent> diaryCommentContentList, int likeCount, int commentCount){
public static DiaryInteractionsDto of(List<DiaryCommentContent> diaryCommentContentList, int likeCount, int commentCount, boolean myLike){
return new DiaryInteractionsDto(
diaryCommentContentList,
likeCount,
commentCount
commentCount,
myLike
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,12 @@ public BaseResponseDto<Void> settingMyVeggieDiary(
);
return BaseResponseDto.of(SuccessCode.SUCCESS,null);
}

@Transactional
public BaseResponseDto<CheckTodayDiaryResponse> 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> myVeggie = myVeggieRepository.findMyVeggieByIdAndUserId((diaryDeleteDto.getMyVeggieId()), userId);
Expand All @@ -80,19 +78,16 @@ public void eraseDiary(DiaryDeleteDto diaryDeleteDto, Long userId){
validateDiaryDelete(diary, diaryDeleteDto.getDiaryId());
diaryRepository.deleteDiaryById(diaryDeleteDto.getDiaryId());
}

public void verifyDiary(Optional<Diary> diary){
if(diary.isEmpty()){
throw new DiaryNotFoundException("해당 일기는 존재하지 않습니다.", MyVeggieGardenErrorCode.NOT_FOUND_DIARY);
}
}

public void validateDiaryDelete(Optional<Diary> diary, Long diaryId){
if(!diary.get().getId().equals(diaryId)){
throw new DiaryAccessDeniedException("해당 일기 접근권한이 없습니다.", MyVeggieGardenErrorCode.NO_ACCESS_DIARY);
}
}

public void verifyMyVeggie(Optional<MyVeggie> myVeggie){
if(myVeggie.isEmpty()){
throw new MyVeggieNotFoundException("존재하지 않는 채소입니다.",MyVeggieGardenErrorCode.NOT_FOUND_VEGGIE);
Expand All @@ -104,7 +99,6 @@ public List<FarmClubDiary> findDiaryAccordingToFarmClub(Long farmClubId, Long us
List<FarmClubDiary> proccessData = proccessFarmClubData(diaryList);
return proccessData;
}

private List<FarmClubDiary> proccessFarmClubData(List<SortedMyLikeDiary> diaryAllList){
return diaryAllList.stream().map(allDiary -> {
User user = allDiary.getDiary().getMyVeggie().getUser();
Expand All @@ -118,19 +112,16 @@ private List<FarmClubDiary> proccessFarmClubData(List<SortedMyLikeDiary> diaryAl
allDiary.getDiary().getState()
);}).toList();
}

@Transactional
public List<AllDairy> selectDiaryAll(MyVeggie myVeggie, Long userId) {
List<SortedMyLikeDiary> diaryList = diaryRepository.findDiariesByMyVeggie(myVeggie, userId);
return AllDairy.processData(diaryList);
}

@Transactional
public MyVeggieDiaryCount selectDiaryCount(MyVeggie myVeggie) {
List<Diary> diaryList = myVeggieRepository.findDiariesByMyVeggie(myVeggie);
return MyVeggieDiaryCount.processData(diaryList);
}

@Transactional
public void pressLike(Long userId, Long diaryId) {
Optional<DiaryLike> diaryLike = diaryLikeRepository.findDiaryLikeByDiaryIdAndUserId(diaryId, userId);
Expand All @@ -139,34 +130,29 @@ public void pressLike(Long userId, Long diaryId) {
Diary diaryData = selectDiaryById(diaryId);
insertLike(userData, diaryData);
}

public void checkLikeData(Optional<DiaryLike> 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<DiaryComment> diaryCommentData = myVeggieRepository.findDiaryCommentByIdAndUserId(diaryCommentId, user);
validateDiaryComment(diaryCommentData);
myVeggieRepository.deleteDiaryCommentByIdAndUserId(diaryCommentId, user);
}

@Transactional
public void updateComment(User user, Long diaryCommentId, String content) {
Optional<DiaryComment> diaryCommentData = myVeggieRepository.findDiaryCommentByIdAndUserId(diaryCommentId, user);
Expand All @@ -186,15 +172,14 @@ public BaseResponseDto<SelectDiaryOneResponse> selectDiaryOne(MyVeggie myVeggie)
DateManager.formatDate(diaryList.get(0).getCreatedDate())
));
}


@Transactional
public DiaryInteractionsDto selectComment(Long userId, Long diaryId) {
List<DiaryComment> diaryCommentList = diaryRepository.findDiaryById(diaryId);
List<DiaryCommentContent> diaryCommentContent = DiaryCommentContent.processData(diaryCommentList, userId);
int likeCount = diaryLikeRepository.findDiaryLikeCountById(diaryId);
int commentCount = diaryCommentRepository.findDiaryCommentCountById(diaryId);
return DiaryInteractionsDto.of(diaryCommentContent,likeCount,commentCount);
Optional<DiaryLike> 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);
Expand Down
Loading