From 8a0e4a47b39e57a5129e3a7a3ae430aba1c54723 Mon Sep 17 00:00:00 2001 From: sichoi42 <42.4.sichoi@gmail.com> Date: Tue, 20 Aug 2024 22:12:56 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=EC=9E=90=EC=84=9C=EC=A0=84=20=EC=83=81?= =?UTF-8?q?=EC=84=B8/=EC=A0=84=EC=B2=B4=20=EC=A1=B0=ED=9A=8C=20API=20?= =?UTF-8?q?=EC=9D=91=EB=8B=B5=EC=97=90=20interviewId=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dto/response/AutobiographyDetailResponseDto.java | 3 +++ .../dto/response/AutobiographyPreviewDto.java | 3 +++ .../repository/AutobiographyRepository.java | 6 ++++++ .../service/AutobiographyQueryService.java | 12 ++++++++---- .../lifebookshelf/mapper/AutobiographyMapper.java | 8 ++++++-- 5 files changed, 26 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/lifelibrarians/lifebookshelf/autobiography/dto/response/AutobiographyDetailResponseDto.java b/src/main/java/com/lifelibrarians/lifebookshelf/autobiography/dto/response/AutobiographyDetailResponseDto.java index e44b595..c33d36c 100644 --- a/src/main/java/com/lifelibrarians/lifebookshelf/autobiography/dto/response/AutobiographyDetailResponseDto.java +++ b/src/main/java/com/lifelibrarians/lifebookshelf/autobiography/dto/response/AutobiographyDetailResponseDto.java @@ -17,6 +17,9 @@ public class AutobiographyDetailResponseDto { @Schema(description = "자서전 ID", example = "1") private final Long autobiographyId; + @Schema(description = "인터뷰 ID", example = "1") + private final Long interviewId; + @Schema(description = "자서전 제목", example = "My Early Life") private final String title; diff --git a/src/main/java/com/lifelibrarians/lifebookshelf/autobiography/dto/response/AutobiographyPreviewDto.java b/src/main/java/com/lifelibrarians/lifebookshelf/autobiography/dto/response/AutobiographyPreviewDto.java index 0d71ac5..828a099 100644 --- a/src/main/java/com/lifelibrarians/lifebookshelf/autobiography/dto/response/AutobiographyPreviewDto.java +++ b/src/main/java/com/lifelibrarians/lifebookshelf/autobiography/dto/response/AutobiographyPreviewDto.java @@ -17,6 +17,9 @@ public class AutobiographyPreviewDto { @Schema(description = "자서전 ID", example = "1") private final Long autobiographyId; + @Schema(description = "인터뷰 ID", example = "1") + private final Long interviewId; + @Schema(description = "대응되는 챕터 ID", example = "1") private final Long chapterId; diff --git a/src/main/java/com/lifelibrarians/lifebookshelf/autobiography/repository/AutobiographyRepository.java b/src/main/java/com/lifelibrarians/lifebookshelf/autobiography/repository/AutobiographyRepository.java index 1c0df48..e8db2a5 100644 --- a/src/main/java/com/lifelibrarians/lifebookshelf/autobiography/repository/AutobiographyRepository.java +++ b/src/main/java/com/lifelibrarians/lifebookshelf/autobiography/repository/AutobiographyRepository.java @@ -14,4 +14,10 @@ public interface AutobiographyRepository extends JpaRepository findByChapterId(Long chapterId); + + @Query("SELECT a FROM Autobiography a JOIN FETCH a.autobiographyInterviews WHERE a.id = :autobiographyId") + Optional findWithInterviewById(Long autobiographyId); + + @Query("SELECT a FROM Autobiography a JOIN FETCH a.autobiographyInterviews WHERE a.member.id = :memberId") + List findWithInterviewByMemberId(Long memberId); } diff --git a/src/main/java/com/lifelibrarians/lifebookshelf/autobiography/service/AutobiographyQueryService.java b/src/main/java/com/lifelibrarians/lifebookshelf/autobiography/service/AutobiographyQueryService.java index 3dd7a7a..d295c7e 100644 --- a/src/main/java/com/lifelibrarians/lifebookshelf/autobiography/service/AutobiographyQueryService.java +++ b/src/main/java/com/lifelibrarians/lifebookshelf/autobiography/service/AutobiographyQueryService.java @@ -98,11 +98,14 @@ private List getSubchapterDtos(Long parentChapterId) { } public AutobiographyListResponseDto getAutobiographies(Long memberId) { - List autobiographies = autobiographyRepository.findByMemberId(memberId); + List autobiographies = autobiographyRepository.findWithInterviewByMemberId( + memberId); List autobiographyPreviewDtos = autobiographies.stream() .map((Autobiography autobiography) -> autobiographyMapper.toAutobiographyPreviewDto( autobiography, - autobiography.getChapter().getId())) + autobiography.getChapter().getId(), + autobiography.getAutobiographyInterviews().get(0).getId() + )) .collect(Collectors.toList()); return AutobiographyListResponseDto.builder() .results(autobiographyPreviewDtos) @@ -110,12 +113,13 @@ public AutobiographyListResponseDto getAutobiographies(Long memberId) { } public AutobiographyDetailResponseDto getAutobiography(Long memberId, Long autobiographyId) { - Autobiography autobiography = autobiographyRepository.findById(autobiographyId) + Autobiography autobiography = autobiographyRepository.findWithInterviewById(autobiographyId) .orElseThrow( AutobiographyExceptionStatus.AUTOBIOGRAPHY_NOT_FOUND::toServiceException); if (!autobiography.getMember().getId().equals(memberId)) { throw AutobiographyExceptionStatus.AUTOBIOGRAPHY_NOT_OWNER.toServiceException(); } - return autobiographyMapper.toAutobiographyDetailResponseDto(autobiography); + return autobiographyMapper.toAutobiographyDetailResponseDto(autobiography, + autobiography.getAutobiographyInterviews().get(0).getId()); } } diff --git a/src/main/java/com/lifelibrarians/lifebookshelf/mapper/AutobiographyMapper.java b/src/main/java/com/lifelibrarians/lifebookshelf/mapper/AutobiographyMapper.java index 1aecaf7..65c381c 100644 --- a/src/main/java/com/lifelibrarians/lifebookshelf/mapper/AutobiographyMapper.java +++ b/src/main/java/com/lifelibrarians/lifebookshelf/mapper/AutobiographyMapper.java @@ -24,12 +24,16 @@ protected String mapImageUrl(String profileImageUrl) { @Mapping(source = "autobiography.content", target = "contentPreview", qualifiedByName = "truncate") @Mapping(source = "autobiography.coverImageUrl", target = "coverImageUrl", qualifiedByName = "mapImageUrl") public abstract AutobiographyPreviewDto toAutobiographyPreviewDto(Autobiography autobiography, - Long chapterId); + Long chapterId, + Long interviewId + ); @Mapping(source = "autobiography.id", target = "autobiographyId") @Mapping(source = "autobiography.coverImageUrl", target = "coverImageUrl", qualifiedByName = "mapImageUrl") public abstract AutobiographyDetailResponseDto toAutobiographyDetailResponseDto( - Autobiography autobiography); + Autobiography autobiography, + Long interviewId + ); @Named("truncate") String truncateContent(String content) {