-
Notifications
You must be signed in to change notification settings - Fork 5
Hotfix/mateboard: 게시글 좋아요, 댓글 좋아요 배열 반영 #179
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
Changes from all commits
ec79244
9c6b30a
71773f0
04a7544
2063919
4561250
8c14602
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| package com.frend.planit.domain.mateboard.comment.dto.response; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 새로운 DTO |
||
|
|
||
| import lombok.AllArgsConstructor; | ||
| import lombok.Getter; | ||
|
|
||
| /** | ||
| * 댓글 좋아요 정보를 담는 DTO입니다. | ||
| * <p>authorId(사용자)와 commentId(댓글 ID)를 포함합니다.</p> | ||
| */ | ||
| @Getter | ||
| @AllArgsConstructor | ||
| public class CommentLikeInfo { | ||
|
|
||
| private Long authorId; | ||
| private Long commentId; | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,7 @@ | ||
| package com.frend.planit.domain.mateboard.comment.dto.response; | ||
|
|
||
| import java.time.LocalDateTime; | ||
| import java.util.List; | ||
| import lombok.Builder; | ||
| import lombok.Getter; | ||
|
|
||
|
|
@@ -30,6 +31,8 @@ public class MateCommentResponseDto { | |
|
|
||
| private final String content; | ||
|
|
||
| private final List<CommentLikeInfo> commentLike; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
|
||
| private final LocalDateTime createdAt; | ||
|
|
||
| private final LocalDateTime modifiedAt; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,12 +4,16 @@ | |
| import com.frend.planit.domain.user.entity.User; | ||
| import com.frend.planit.global.base.BaseTime; | ||
| import jakarta.persistence.AttributeOverride; | ||
| import jakarta.persistence.CascadeType; | ||
| import jakarta.persistence.Column; | ||
| import jakarta.persistence.Entity; | ||
| import jakarta.persistence.FetchType; | ||
| import jakarta.persistence.JoinColumn; | ||
| import jakarta.persistence.ManyToOne; | ||
| import jakarta.persistence.OneToMany; | ||
| import jakarta.persistence.Table; | ||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
| import lombok.Getter; | ||
| import lombok.Setter; | ||
|
|
||
|
|
@@ -47,4 +51,6 @@ public class MateComment extends BaseTime { | |
| @Column(nullable = false) | ||
| private String content; | ||
|
|
||
| @OneToMany(mappedBy = "mateComment", cascade = CascadeType.ALL, orphanRemoval = true) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| private List<MateCommentLike> commentLikes = new ArrayList<>(); | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,9 @@ | ||
| package com.frend.planit.domain.mateboard.comment.mapper; | ||
|
|
||
| import com.frend.planit.domain.mateboard.comment.dto.response.CommentLikeInfo; | ||
| import com.frend.planit.domain.mateboard.comment.dto.response.MateCommentResponseDto; | ||
| import com.frend.planit.domain.mateboard.comment.entity.MateComment; | ||
| import java.util.List; | ||
|
|
||
| /** | ||
| * MateComment 엔티티를 MateCommentResponseDto로 변환하는 매퍼 클래스입니다. | ||
|
|
@@ -14,7 +16,8 @@ | |
| */ | ||
| public class MateCommentMapper { | ||
|
|
||
| public static MateCommentResponseDto toResponseDto(MateComment comment) { | ||
| public static MateCommentResponseDto toResponseDto(MateComment comment, | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| List<CommentLikeInfo> commentLike) { | ||
| return MateCommentResponseDto.builder() | ||
| .mateCommentId(comment.getId()) | ||
| .matePostId(comment.getMate().getId()) | ||
|
|
@@ -23,9 +26,13 @@ public static MateCommentResponseDto toResponseDto(MateComment comment) { | |
| .nickname(comment.getUser().getNickname()) | ||
| .profileImageUrl(comment.getUser().getProfileImageUrl()) | ||
| .content(comment.getContent()) | ||
| .commentLike(commentLike) | ||
| .createdAt(comment.getCreatedAt()) | ||
| .modifiedAt(comment.getModifiedAt()) | ||
| // TODO: 좋아요 수 추가 | ||
| .build(); | ||
| } | ||
|
|
||
| public static MateCommentResponseDto toResponseDto(MateComment comment) { | ||
| return toResponseDto(comment, List.of()); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,6 +5,7 @@ | |
| import static com.frend.planit.global.response.ErrorType.USER_NOT_FOUND; | ||
|
|
||
| import com.frend.planit.domain.mateboard.comment.dto.request.MateCommentRequestDto; | ||
| import com.frend.planit.domain.mateboard.comment.dto.response.CommentLikeInfo; | ||
| import com.frend.planit.domain.mateboard.comment.dto.response.MateCommentResponseDto; | ||
| import com.frend.planit.domain.mateboard.comment.entity.MateComment; | ||
| import com.frend.planit.domain.mateboard.comment.mapper.MateCommentMapper; | ||
|
|
@@ -95,8 +96,17 @@ public PageResponse<MateCommentResponseDto> findAllByMateIdWithPaging(Long mateI | |
| Mate mate = mateService.findMateOrThrow(mateId); | ||
| // 2. 해당 게시글에 달린 댓글을 페이징하여 조회 | ||
| Page<MateComment> comments = mateCommentRepository.findAllByMate(mate, pageable); | ||
| // 3. Entity -> DTO 변환 | ||
| Page<MateCommentResponseDto> dtoPage = comments.map(MateCommentMapper::toResponseDto); | ||
| // 3. Entity -> DTO 변환 (commentLike 포함) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| Page<MateCommentResponseDto> dtoPage = comments.map(comment -> { | ||
| List<CommentLikeInfo> commentLikes = comment.getCommentLikes().stream() | ||
| .map(like -> new CommentLikeInfo( | ||
| like.getUser().getId(), | ||
| like.getMateComment().getId() | ||
| )).toList(); | ||
|
|
||
| return MateCommentMapper.toResponseDto(comment, commentLikes); | ||
| }); | ||
|
|
||
| // 4. PageResponse로 감싸서 반환 | ||
| return new PageResponse<>(dtoPage); | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| package com.frend.planit.domain.mateboard.post.dto.response; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 댓글 좋아요 정보를 담는 DTO인 |
||
|
|
||
| import lombok.AllArgsConstructor; | ||
| import lombok.Getter; | ||
|
|
||
| /** | ||
| * 댓글 좋아요 정보를 담는 DTO입니다. | ||
| * <p>작성자(authorId)가 어떤 댓글(commentId)에 좋아요를 눌렀는지 나타냅니다.</p> | ||
| */ | ||
| @Getter | ||
| @AllArgsConstructor | ||
| public class CommentLikeInfo { | ||
|
|
||
| private Long authorId; | ||
| private Long commentId; | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| package com.frend.planit.domain.mateboard.post.dto.response; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 새로운 DTO |
||
|
|
||
| import lombok.AllArgsConstructor; | ||
| import lombok.Getter; | ||
|
|
||
| /** | ||
| * 동행 신청 정보를 담는 DTO입니다. | ||
| * <p>작성자(authorId)가 어떤 동행 신청(applicationId)을 했는지 나타냅니다.</p> | ||
| */ | ||
| @Getter | ||
| @AllArgsConstructor | ||
| public class MateApplicationInfo { | ||
|
|
||
| private Long authorId; | ||
| private Long applicationId; | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,17 +7,19 @@ | |
| import com.querydsl.core.annotations.QueryProjection; | ||
| import java.time.LocalDate; | ||
| import java.time.LocalDateTime; | ||
| import java.util.List; | ||
| import lombok.Builder; | ||
| import lombok.Getter; | ||
|
|
||
| /** | ||
| * 메이트 모집 게시글 조회, 목록 응답 시에 사용하는 Response DTO입니다. | ||
| * | ||
| * <p>상세 조회 시 postLike, mateApplications, isApplied 등의 정보를 포함합니다.</p> | ||
| * | ||
| * @author zelly | ||
| * @version 1.0 | ||
| * @since 2025-03-28 | ||
| */ | ||
| @Builder | ||
| @Getter | ||
| public class MateResponseDto { | ||
|
|
||
|
|
@@ -40,8 +42,10 @@ public class MateResponseDto { | |
| private final int commentCount; | ||
| private final int likeCount; | ||
| private final LocalDateTime createdAt; | ||
| private boolean isApplied; | ||
| private final boolean isApplied; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
|
||
| private final List<PostLikeInfo> postLike; | ||
| private final List<MateApplicationInfo> mateApplications; | ||
|
|
||
| @QueryProjection | ||
| public MateResponseDto(Long matePostId, Long authorId, String title, String content, | ||
|
|
@@ -70,5 +74,40 @@ public MateResponseDto(Long matePostId, Long authorId, String title, String cont | |
| this.likeCount = likeCount; | ||
| this.createdAt = createdAt; | ||
| this.isApplied = isApplied; | ||
| this.postLike = null; | ||
| this.mateApplications = null; | ||
| } | ||
|
|
||
| @Builder | ||
| public MateResponseDto(Long matePostId, Long authorId, String title, String content, | ||
| TravelRegion travelRegion, LocalDate travelStartDate, LocalDate travelEndDate, | ||
| RecruitmentStatus recruitmentStatus, MateGender mateGender, | ||
| int recruitCount, int appliedCount, String imageUrl, | ||
| String nickname, String bio, String profileImage, Gender authorGender, | ||
| int commentCount, int likeCount, LocalDateTime createdAt, | ||
| boolean isApplied, List<PostLikeInfo> postLike, | ||
| List<MateApplicationInfo> mateApplications) { | ||
| this.matePostId = matePostId; | ||
| this.authorId = authorId; | ||
| this.title = title; | ||
| this.content = content; | ||
| this.travelRegion = travelRegion; | ||
| this.travelStartDate = travelStartDate; | ||
| this.travelEndDate = travelEndDate; | ||
| this.recruitmentStatus = recruitmentStatus; | ||
| this.mateGender = mateGender; | ||
| this.recruitCount = recruitCount; | ||
| this.appliedCount = appliedCount; | ||
| this.imageUrl = imageUrl; | ||
| this.nickname = nickname; | ||
| this.bio = bio; | ||
| this.profileImage = profileImage; | ||
| this.authorGender = authorGender; | ||
| this.commentCount = commentCount; | ||
| this.likeCount = likeCount; | ||
| this.createdAt = createdAt; | ||
| this.isApplied = isApplied; | ||
| this.postLike = postLike; | ||
| this.mateApplications = mateApplications; | ||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| package com.frend.planit.domain.mateboard.post.dto.response; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 새로운 DTO |
||
|
|
||
| import lombok.AllArgsConstructor; | ||
| import lombok.Getter; | ||
|
|
||
| /** | ||
| * 게시글 좋아요 정보를 담는 DTO입니다. | ||
| * <p>작성자(authorId)가 어떤 게시글(matePostId)에 좋아요를 눌렀는지 나타냅니다.</p> | ||
| */ | ||
| @Getter | ||
| @AllArgsConstructor | ||
| public class PostLikeInfo { | ||
|
|
||
| private Long authorId; | ||
| private Long matePostId; | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -124,6 +124,9 @@ public class Mate extends BaseTime { | |
| @OneToMany(mappedBy = "mate", cascade = CascadeType.ALL, orphanRemoval = true) | ||
| private List<MateApplication> applications = new ArrayList<>(); | ||
|
|
||
| @OneToMany(mappedBy = "matePost", fetch = FetchType.LAZY) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| private List<MatePostLike> postLikes; | ||
|
|
||
| /** | ||
| * 게시글 생성 날짜(createdAt), 게시글 수정 날짜(modifiedAt) BaseTime 상속 | ||
| */ | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,10 @@ | ||
| package com.frend.planit.domain.mateboard.post.mapper; | ||
|
|
||
| import com.frend.planit.domain.mateboard.post.dto.response.MateApplicationInfo; | ||
| import com.frend.planit.domain.mateboard.post.dto.response.MateResponseDto; | ||
| import com.frend.planit.domain.mateboard.post.dto.response.PostLikeInfo; | ||
| import com.frend.planit.domain.mateboard.post.entity.Mate; | ||
| import java.util.List; | ||
|
|
||
| /** | ||
| * Mate 엔티티를 MateResponseDto로 변환하는 매퍼 클래스입니다. | ||
|
|
@@ -20,8 +23,11 @@ public class MateMapper { | |
| * @param mate 변환할 Mate 엔티티 | ||
| * @return MateResponseDto 변환 결과 | ||
| */ | ||
| public static MateResponseDto toResponseDto(Mate mate, String imageUrl, boolean isApplied) { | ||
| public static MateResponseDto toResponseDto(Mate mate, String imageUrl) { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| return toResponseDto(mate, imageUrl, false); | ||
| } | ||
|
|
||
| public static MateResponseDto toResponseDto(Mate mate, String imageUrl, boolean isApplied) { | ||
| return MateResponseDto.builder() | ||
| .matePostId(mate.getId()) | ||
| .authorId(mate.getWriter().getId()) | ||
|
|
@@ -46,7 +52,36 @@ public static MateResponseDto toResponseDto(Mate mate, String imageUrl, boolean | |
| .build(); | ||
| } | ||
|
|
||
| public static MateResponseDto toResponseDto(Mate mate, String imageUrl) { | ||
| return toResponseDto(mate, imageUrl, false); | ||
| public static MateResponseDto toResponseDto( | ||
| Mate mate, | ||
| String imageUrl, | ||
| boolean isApplied, | ||
| List<PostLikeInfo> postLike, | ||
| List<MateApplicationInfo> mateApplications | ||
| ) { | ||
| return MateResponseDto.builder() | ||
| .matePostId(mate.getId()) | ||
| .authorId(mate.getWriter().getId()) | ||
| .nickname(mate.getWriter().getNickname()) | ||
| .profileImage(mate.getWriter().getProfileImageUrl()) | ||
| .authorGender(mate.getWriter().getGender()) | ||
| .bio(mate.getWriter().getBio()) | ||
| .title(mate.getTitle()) | ||
| .content(mate.getContent()) | ||
| .recruitCount(mate.getRecruitCount()) | ||
| .travelRegion(mate.getTravelRegion()) | ||
| .travelStartDate(mate.getTravelStartDate()) | ||
| .travelEndDate(mate.getTravelEndDate()) | ||
| .recruitmentStatus(mate.getRecruitmentStatus()) | ||
| .mateGender(mate.getMateGender()) | ||
| .appliedCount((int) mate.getApplications().stream() | ||
| .filter(a -> a.getStatus().isAccepted()) | ||
| .count()) | ||
| .imageUrl(imageUrl) | ||
| .createdAt(mate.getCreatedAt()) | ||
| .isApplied(isApplied) | ||
| .postLike(postLike) | ||
| .mateApplications(mateApplications) | ||
| .build(); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,7 +8,9 @@ | |
| import com.frend.planit.domain.image.type.HolderType; | ||
| import com.frend.planit.domain.mateboard.application.repository.MateApplicationRepository; | ||
| import com.frend.planit.domain.mateboard.post.dto.request.MateRequestDto; | ||
| import com.frend.planit.domain.mateboard.post.dto.response.MateApplicationInfo; | ||
| import com.frend.planit.domain.mateboard.post.dto.response.MateResponseDto; | ||
| import com.frend.planit.domain.mateboard.post.dto.response.PostLikeInfo; | ||
| import com.frend.planit.domain.mateboard.post.entity.Mate; | ||
| import com.frend.planit.domain.mateboard.post.mapper.MateMapper; | ||
| import com.frend.planit.domain.mateboard.post.repository.MateQueryRepository; | ||
|
|
@@ -99,8 +101,18 @@ public MateResponseDto getMate(Long id, Long userId) { | |
|
|
||
| boolean isApplied = mateApplicationRepository.existsByMateIdAndApplicantId(id, userId); | ||
|
|
||
| // 1. 게시글 좋아요 정보 → PostLikeInfo 리스트 생성 | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| List<PostLikeInfo> postLike = mate.getPostLikes().stream() | ||
| .map(like -> new PostLikeInfo(like.getUser().getId(), mate.getId())) | ||
| .toList(); | ||
|
|
||
| // 2. 동행 신청 정보 → MateApplicationInfo 리스트 생성 | ||
| List<MateApplicationInfo> mateApplications = mate.getApplications().stream() | ||
| .map(app -> new MateApplicationInfo(app.getApplicant().getId(), app.getId())) | ||
| .toList(); | ||
|
|
||
| // DTO 변환 시 이미지 URL 포함 | ||
| return MateMapper.toResponseDto(mate, imageUrl, isApplied); | ||
| return MateMapper.toResponseDto(mate, imageUrl, isApplied, postLike, mateApplications); | ||
| } | ||
|
|
||
| /** | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
API 경로가
/api/v1/mates/comments에서/api/v1/mateposts/comments로 변경되었습니다./mateposts라는 용어가 더 적절한지 확인하고, 변경 이유를 명시적으로 commit message에 추가해주세요. 다른 부분과의 일관성도 확인해야 합니다.