Skip to content
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 @@ -13,7 +13,7 @@

@RestController
@RequiredArgsConstructor
@RequestMapping("/api/v1/mates/comments")
@RequestMapping("/api/v1/mateposts/comments")
Copy link
Copy Markdown

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에 추가해주세요. 다른 부분과의 일관성도 확인해야 합니다.

public class MateCommentLikeController {

private final MateCommentLikeService mateCommentLikeService;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.frend.planit.domain.mateboard.comment.dto.response;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

새로운 DTO CommentLikeInfo가 추가되었습니다. authorIdcommentId를 사용하는 목적을 명확히 주석으로 설명해주세요. javadoc 스타일 주석을 사용하는 것이 좋습니다.


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;

Expand Down Expand Up @@ -30,6 +31,8 @@ public class MateCommentResponseDto {

private final String content;

private final List<CommentLikeInfo> commentLike;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MateCommentResponseDtocommentLike 필드가 추가되었습니다. List<CommentLikeInfo> 타입을 사용하는 이유와 null 가능성 처리에 대한 고려사항을 추가해주세요. 필요하다면 @NotNull과 같은 어노테이션을 사용하는 것도 고려해보세요.


private final LocalDateTime createdAt;

private final LocalDateTime modifiedAt;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -47,4 +51,6 @@ public class MateComment extends BaseTime {
@Column(nullable = false)
private String content;

@OneToMany(mappedBy = "mateComment", cascade = CascadeType.ALL, orphanRemoval = true)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MateComment 엔티티에 commentLikes 필드가 추가되었습니다. CascadeType.ALLorphanRemoval = true를 사용하는 이유를 명확히 설명해주세요. 관계 설정의 의도와 잠재적인 문제점(예: 무한 루프, 성능 저하)에 대한 고려사항을 추가하는 것이 좋습니다.

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로 변환하는 매퍼 클래스입니다.
Expand All @@ -14,7 +16,8 @@
*/
public class MateCommentMapper {

public static MateCommentResponseDto toResponseDto(MateComment comment) {
public static MateCommentResponseDto toResponseDto(MateComment comment,
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MateCommentMappertoResponseDto 메서드가 수정되었습니다. 기존 메서드가 삭제되고, commentLike 리스트를 파라미터로 받는 새로운 메서드가 추가되었습니다. 기존의 // TODO: 좋아요 수 추가 부분은 제거되었는데, 좋아요 수를 추가할 필요가 없어진 이유를 설명해주세요. 또한, 기본값으로 빈 리스트를 전달하는 오버로딩 메서드를 추가한 부분은 필요성을 재고해볼 필요가 있습니다. 빈 리스트를 전달하는 경우와 실제 데이터가 있는 경우의 차이점을 고려하여 더 효율적인 방법을 찾아보는 것이 좋습니다.

List<CommentLikeInfo> commentLike) {
return MateCommentResponseDto.builder()
.mateCommentId(comment.getId())
.matePostId(comment.getMate().getId())
Expand All @@ -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
Expand Up @@ -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;
Expand Down Expand Up @@ -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 포함)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MateCommentServicecommentsMateCommentResponseDto로 변환하는 부분이 수정되었습니다. 이제 commentLikes 정보를 포함하여 변환하는데, 이 변경으로 인해 성능에 미치는 영향을 고려해보아야 합니다. 필요하다면 stream().parallel()을 사용하여 병렬 처리를 고려해 볼 수 있지만, 그로 인한 잠재적인 문제점(예: race condition)도 함께 고려해야 합니다. 또한, commentLikes를 매핑하는 부분을 더 효율적으로 개선할 수 있는지 확인해주세요.

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);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.frend.planit.domain.mateboard.post.dto.response;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

댓글 좋아요 정보를 담는 DTO인 CommentLikeInfo가 추가되었지만, 이미 com.frend.planit.domain.mateboard.comment.dto.response.CommentLikeInfo가 존재합니다. 중복 정의인지, 의도적으로 다른 패키지에 동일한 이름의 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;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

새로운 DTO MateApplicationInfo가 추가되었습니다. authorIdapplicationId의 의미를 명확하게 주석으로 설명하고, javadoc 스타일 주석을 사용하는 것이 좋습니다.


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
Expand Up @@ -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 {

Expand All @@ -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;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MateResponseDtoisApplied, postLike, mateApplications 필드가 추가되었습니다. final 키워드를 사용하여 변경 불가능하게 만든 이유와 각 필드의 null 가능성 처리에 대한 고려사항을 추가해주세요. 필요에 따라 @NotNull 등의 어노테이션을 사용할 수 있습니다. 또한 Builder 패턴을 사용하는 이유도 명시적으로 설명하는 것이 좋습니다.


private final List<PostLikeInfo> postLike;
private final List<MateApplicationInfo> mateApplications;

@QueryProjection
public MateResponseDto(Long matePostId, Long authorId, String title, String content,
Expand Down Expand Up @@ -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;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

새로운 DTO PostLikeInfo가 추가되었습니다. authorIdmatePostId의 의미를 명확하게 주석으로 설명하고, javadoc 스타일 주석을 사용하는 것이 좋습니다.


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
Expand Up @@ -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)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mate 엔티티에 postLikes 필드가 추가되었습니다. FetchType.LAZY를 사용한 이유와 postLikes 리스트의 관리에 대한 고려사항(예: CascadeType 설정)을 명확히 주석으로 설명해주세요. lazy loading으로 인한 N+1 문제 발생 가능성을 고려하고, 필요하다면 @Fetch 어노테이션 사용 또는 JPQL 쿼리 최적화를 고려해야 합니다.

private List<MatePostLike> postLikes;

/**
* 게시글 생성 날짜(createdAt), 게시글 수정 날짜(modifiedAt) BaseTime 상속
*/
Expand Down
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로 변환하는 매퍼 클래스입니다.
Expand All @@ -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) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MateMappertoResponseDto 메서드가 수정되었습니다. 기존 메서드가 오버로딩 되어, isApplied, postLike, mateApplications 파라미터를 받는 새로운 메서드가 추가되었습니다. isApplied의 기본값을 false로 설정한 이유와 postLike, mateApplications를 추가한 이유를 명확히 설명해야 합니다. 메서드 내 로직이 복잡해졌으므로, 가독성을 높이기 위해 코드를 더 작은 함수로 분해하는 것을 고려해보세요.

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())
Expand All @@ -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
Expand Up @@ -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;
Expand Down Expand Up @@ -99,8 +101,18 @@ public MateResponseDto getMate(Long id, Long userId) {

boolean isApplied = mateApplicationRepository.existsByMateIdAndApplicantId(id, userId);

// 1. 게시글 좋아요 정보 → PostLikeInfo 리스트 생성
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MateService에서 MateResponseDto를 생성하는 로직이 변경되었습니다. postLikemateApplications 정보를 추가하여 MateMapper에 전달하는데, 이 부분의 성능에 대한 고려가 필요합니다. stream() 연산의 효율성을 확인하고, 필요하다면 최적화 방안을 강구해야 합니다. 또한, 변경 전과 변경 후의 성능 차이를 측정하고 비교하는 것이 좋습니다. 각 리스트 생성 부분에 대한 주석을 더 자세히 추가하는 것을 추천합니다.

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);
}

/**
Expand Down