Skip to content

Commit

Permalink
[feat] getMyPost
Browse files Browse the repository at this point in the history
  • Loading branch information
gol2580 committed Feb 1, 2024
1 parent 85a0f01 commit 039bd82
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -41,6 +42,7 @@ public static GetSettingPostDto toDto(Long postId, String content, String writer
.writerProfileImg(writerProfileImg)
.likeCount(likeCount)
.commentCount(commentCount)
.isLiked(isLiked)
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ public CalendarDetailDto dtoBuilderWithNoImg(Long postId, String nickname, Strin

public boolean isLiked(List<Likes> likesList,Member member) {
for(Likes like : likesList) {
if(like.getLikeId().equals(member.getMemberId())) {
if(like.getMember().getMemberId().equals(member.getMemberId())) {
return true;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,17 +149,27 @@ public List<GetSettingPostDto> getMyPost() {
List<GetSettingPostDto> dto = new ArrayList<>();
for (Post post : posts) {
Long countLike = likeRepository.countLike(post.getPostId());
List<Likes> 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<Likes> likesList, Member member) {
for(Likes like : likesList) {
if(like.getMember().getMemberId().equals(member.getMemberId())) {
return true;
}
}
return false;
}

}

0 comments on commit 039bd82

Please sign in to comment.