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 @@ -27,4 +27,6 @@ public interface MateApplicationRepository extends JpaRepository<MateApplication
* @return
*/
Optional<MateApplication> findByMateIdAndApplicantId(Long mateId, Long userId);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

좋은 추가입니다. MateApplication 엔티티에 대한 존재 여부를 효율적으로 확인할 수 있는 메서드가 추가되었습니다. 메서드 이름도 명확하고 좋습니다.

boolean existsByMateIdAndApplicantId(Long mateId, Long applicantId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,9 @@ public PageResponse<MateResponseDto> searchMatePosts(
*/
@GetMapping("/{id}")
@ResponseStatus(HttpStatus.OK)
public MateResponseDto getMate(@PathVariable Long id) {
return mateService.getMate(id);
public MateResponseDto getMate(@PathVariable Long id,
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

getMate 메서드에 사용자 ID (userId)를 추가한 것은 긍정적입니다. 이제 특정 게시글에 사용자가 지원했는지 여부를 확인하는 데 필요한 정보를 서비스 계층에 전달할 수 있습니다. @AuthenticationPrincipal 어노테이션 사용도 적절합니다.

@AuthenticationPrincipal Long userId) {
return mateService.getMate(id, userId);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,16 @@ public class MateResponseDto {
private final int commentCount;
private final int likeCount;
private final LocalDateTime createdAt;
private 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.

isApplied 필드를 추가하여 사용자가 해당 모임에 지원했는지 여부를 표시하는 것은 매우 좋습니다. DTO에 필요한 정보가 명확하게 추가되었습니다. 생성자와 setter도 잘 업데이트 되었습니다.



@QueryProjection
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) {
int commentCount, int likeCount, LocalDateTime createdAt, boolean isApplied) {
this.matePostId = matePostId;
this.authorId = authorId;
this.title = title;
Expand All @@ -67,5 +69,6 @@ public MateResponseDto(Long matePostId, Long authorId, String title, String cont
this.commentCount = commentCount;
this.likeCount = likeCount;
this.createdAt = createdAt;
this.isApplied = isApplied;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,15 @@ public class MateMapper {
* @param mate 변환할 Mate 엔티티
* @return MateResponseDto 변환 결과
*/
public static MateResponseDto toResponseDto(Mate mate, String imageUrl) {
public static MateResponseDto toResponseDto(Mate mate, String imageUrl, 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.

기존의 toResponseDto 메서드를 오버로드하여 isApplied 값을 처리하도록 수정한 것은 효율적입니다. 기존 메서드는 기본값으로 isApplied를 false로 설정하는 새로운 메서드를 호출하여 코드 중복을 방지합니다. 가독성과 유지보수성이 향상되었습니다.


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())
Expand All @@ -41,6 +42,11 @@ public static MateResponseDto toResponseDto(Mate mate, String imageUrl) {
.count())
.imageUrl(imageUrl)
.createdAt(mate.getCreatedAt())
.isApplied(isApplied)
.build();
}

public static MateResponseDto toResponseDto(Mate mate, String imageUrl) {
return toResponseDto(mate, imageUrl, false);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import static com.frend.planit.domain.mateboard.post.entity.QMatePostLike.matePostLike;

import com.frend.planit.domain.image.entity.QImage;
import com.frend.planit.domain.image.type.HolderType;
import com.frend.planit.domain.mateboard.application.entity.MateApplicationStatus;
import com.frend.planit.domain.mateboard.application.entity.QMateApplication;
import com.frend.planit.domain.mateboard.post.dto.response.MateResponseDto;
Expand Down Expand Up @@ -100,6 +101,8 @@ public Page<MateResponseDto> searchMatePosts(String keyword, String status, Stri
JPAExpressions
.select(image.url)
.from(image)
.where(image.holderType.eq(HolderType.MATEBOARD)
.and(image.holderId.eq(mate.id)))
.orderBy(image.id.asc())
.limit(1),
user.nickname,
Expand All @@ -108,7 +111,8 @@ public Page<MateResponseDto> searchMatePosts(String keyword, String status, Stri
user.gender,
mateComment.countDistinct().intValue(),
matePostLike.countDistinct().intValue(),
mate.createdAt
mate.createdAt,
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Expressions.constant(false) 를 추가하여 기본적으로 지원하지 않은 상태로 설정하는 것은 논리적으로 일관성이 있습니다. 쿼리 결과에 isApplied 필드를 추가하여 서비스 계층에서 불필요한 처리를 줄였습니다. 명확한 의도를 보여줍니다.

Expressions.constant(false)
))
.from(mate)
.leftJoin(mate.writer, user)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import com.frend.planit.domain.image.service.ImageService;
import com.frend.planit.domain.image.type.HolderType;
import com.frend.planit.domain.mateboard.application.repository.MateApplicationRepository;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

MateApplicationRepository 의존성 주입은 적절하며, getMate 메서드에 사용자 ID를 추가하여 isApplied 여부를 확인하는 로직을 추가한 부분이 매우 좋습니다. 코드의 가독성과 유지보수성이 향상되었습니다. mateApplicationRepository를 사용하여 isApplied 값을 효율적으로 가져오는 방식도 효율적입니다.

import com.frend.planit.domain.mateboard.post.dto.request.MateRequestDto;
import com.frend.planit.domain.mateboard.post.dto.response.MateResponseDto;
import com.frend.planit.domain.mateboard.post.entity.Mate;
Expand Down Expand Up @@ -41,6 +42,7 @@ public class MateService {
private final MateRepository mateRepository;
private final UserRepository userRepository;
private final ImageService imageService;
private final MateApplicationRepository mateApplicationRepository;

/**
* ID로 게시글을 조회하고, 존재하지 않으면 예외를 던집니다.
Expand Down Expand Up @@ -89,14 +91,16 @@ public Long createMate(Long userId, MateRequestDto mateRequestDto) {
* @return 조회된 게시글의 응답 DTO
* @throws RuntimeException 해당 ID의 게시글이 존재하지 않을 경우 예외 발생
*/
public MateResponseDto getMate(Long id) {
public MateResponseDto getMate(Long id, Long userId) {
Mate mate = findMateOrThrow(id);

// 게시글 이미지 조회
String imageUrl = imageService.getImage(HolderType.MATEBOARD, mate.getId()).imageUrl();

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

// DTO 변환 시 이미지 URL 포함
return MateMapper.toResponseDto(mate, imageUrl);
return MateMapper.toResponseDto(mate, imageUrl, isApplied);
}

/**
Expand Down