Skip to content

Commit

Permalink
feat: 자서전 상세/전체 조회 API 응답에 interviewId 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
sichoi42 committed Aug 20, 2024
1 parent 45b155d commit 8a0e4a4
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,10 @@ public interface AutobiographyRepository extends JpaRepository<Autobiography, Lo

@Query("SELECT a FROM Autobiography a JOIN FETCH a.chapter WHERE a.chapter.id = :chapterId")
Optional<Autobiography> findByChapterId(Long chapterId);

@Query("SELECT a FROM Autobiography a JOIN FETCH a.autobiographyInterviews WHERE a.id = :autobiographyId")
Optional<Autobiography> findWithInterviewById(Long autobiographyId);

@Query("SELECT a FROM Autobiography a JOIN FETCH a.autobiographyInterviews WHERE a.member.id = :memberId")
List<Autobiography> findWithInterviewByMemberId(Long memberId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -98,24 +98,28 @@ private List<SubchapterDto> getSubchapterDtos(Long parentChapterId) {
}

public AutobiographyListResponseDto getAutobiographies(Long memberId) {
List<Autobiography> autobiographies = autobiographyRepository.findByMemberId(memberId);
List<Autobiography> autobiographies = autobiographyRepository.findWithInterviewByMemberId(
memberId);
List<AutobiographyPreviewDto> 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)
.build();
}

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());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 8a0e4a4

Please sign in to comment.