From 039bd828b801cd095ccb1238a79747933e4e6979 Mon Sep 17 00:00:00 2001 From: gol2580 Date: Thu, 1 Feb 2024 16:01:07 +0900 Subject: [PATCH] [feat] getMyPost --- .../profile/dto/Profile/GetSettingPostDto.java | 6 ++++-- .../domain/profile/service/CalendarService.java | 2 +- .../domain/profile/service/ProfileService.java | 16 +++++++++++++--- 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/kimgreen/backend/domain/profile/dto/Profile/GetSettingPostDto.java b/src/main/java/com/kimgreen/backend/domain/profile/dto/Profile/GetSettingPostDto.java index 8974e87..a5aba98 100644 --- a/src/main/java/com/kimgreen/backend/domain/profile/dto/Profile/GetSettingPostDto.java +++ b/src/main/java/com/kimgreen/backend/domain/profile/dto/Profile/GetSettingPostDto.java @@ -20,7 +20,7 @@ public class GetSettingPostDto { private String imgUrl; private boolean isLiked; - public static GetSettingPostDto toDto(Long postId, String content, String writerBadge, String writerNickname, String writerProfileImg, Long likeCount, Long commentCount, String imgUrl) { + public static GetSettingPostDto toDto(Long postId, String content, String writerBadge, String writerNickname, String writerProfileImg, Long likeCount, Long commentCount, String imgUrl, boolean isLiked) { return GetSettingPostDto.builder() .postId(postId) .content(content) @@ -30,9 +30,10 @@ public static GetSettingPostDto toDto(Long postId, String content, String writer .likeCount(likeCount) .commentCount(commentCount) .imgUrl(imgUrl) + .isLiked(isLiked) .build(); } - public static GetSettingPostDto toDto(Long postId, String content, String writerBadge, String writerNickname, String writerProfileImg, Long likeCount, Long commentCount) { + public static GetSettingPostDto toDto(Long postId, String content, String writerBadge, String writerNickname, String writerProfileImg, Long likeCount, Long commentCount, boolean isLiked) { return GetSettingPostDto.builder() .postId(postId) .content(content) @@ -41,6 +42,7 @@ public static GetSettingPostDto toDto(Long postId, String content, String writer .writerProfileImg(writerProfileImg) .likeCount(likeCount) .commentCount(commentCount) + .isLiked(isLiked) .build(); } } diff --git a/src/main/java/com/kimgreen/backend/domain/profile/service/CalendarService.java b/src/main/java/com/kimgreen/backend/domain/profile/service/CalendarService.java index b0b113b..4a0124b 100644 --- a/src/main/java/com/kimgreen/backend/domain/profile/service/CalendarService.java +++ b/src/main/java/com/kimgreen/backend/domain/profile/service/CalendarService.java @@ -146,7 +146,7 @@ public CalendarDetailDto dtoBuilderWithNoImg(Long postId, String nickname, Strin public boolean isLiked(List likesList,Member member) { for(Likes like : likesList) { - if(like.getLikeId().equals(member.getMemberId())) { + if(like.getMember().getMemberId().equals(member.getMemberId())) { return true; } } diff --git a/src/main/java/com/kimgreen/backend/domain/profile/service/ProfileService.java b/src/main/java/com/kimgreen/backend/domain/profile/service/ProfileService.java index 3ac65ba..ba9725b 100644 --- a/src/main/java/com/kimgreen/backend/domain/profile/service/ProfileService.java +++ b/src/main/java/com/kimgreen/backend/domain/profile/service/ProfileService.java @@ -149,17 +149,27 @@ public List getMyPost() { List dto = new ArrayList<>(); for (Post post : posts) { Long countLike = likeRepository.countLike(post.getPostId()); + List likes = post.getLikes(); + boolean isLiked = isLiked(likes, member); Long countComment = commentRepository.countComment(post.getPostId()); PostImg postImg = postImgRepository.findByPost(post); - //Long postId, String content, String writerBadge, String writerNickname, String writerProfileImg, int likeCount, int commentCount, String imgUrl if (postImg != null) { - dto.add(GetSettingPostDto.toDto(post.getPostId(), post.getContent(), writerBadge, writer, writerProfileImg, countLike, countComment, s3Service.getFullUrl(postImg.getImgUrl()))); + dto.add(GetSettingPostDto.toDto(post.getPostId(), post.getContent(), writerBadge, writer, writerProfileImg, countLike, countComment, s3Service.getFullUrl(postImg.getImgUrl()),isLiked)); } else { - dto.add(GetSettingPostDto.toDto(post.getPostId(), post.getContent(), writerBadge, writer, writerProfileImg, countLike, countComment)); + dto.add(GetSettingPostDto.toDto(post.getPostId(), post.getContent(), writerBadge, writer, writerProfileImg, countLike, countComment,isLiked)); } } return dto; } + public boolean isLiked(List likesList, Member member) { + for(Likes like : likesList) { + if(like.getMember().getMemberId().equals(member.getMemberId())) { + return true; + } + } + return false; + } + }