Skip to content

Commit

Permalink
Merge pull request #201 from MoneyMakersClub/develop
Browse files Browse the repository at this point in the history
[Deploy] 프론트 요구사항에 맞춰 통합조회, 수정 uri 수정
  • Loading branch information
jud1thDev authored Dec 1, 2024
2 parents 1935e18 + f42737f commit 0e37608
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,18 +43,18 @@ public ResponseEntity<?> createArchive(@Valid @RequestBody ArchiveCreateRequestD
return ResponseEntity.ok(responseDto);
}

@GetMapping("/{id}")
@GetMapping("/{archiveId}")
@Operation(summary = "발췌 및 감상평 통합 조회", description = "발췌와 감상평을 조회합니다.")
public ResponseEntity<?> getArchive(@PathVariable("id") final Long id, @RequestParam("type") final ArchiveType archiveType) {
ArchiveResponseDto responseDto = archiveService.getArchive(id, archiveType);
public ResponseEntity<?> getArchive(@PathVariable("archiveId") final Long archiveId) {
ArchiveResponseDto responseDto = archiveService.getArchive(archiveId);
return ResponseEntity.ok(responseDto);
}

@PutMapping("/{id}")
@PutMapping("/{archiveId}")
@Operation(summary = "발췌 및 감상평 통합 수정", description = "발췌와 감상평을 수정합니다.(없던 종류의 독서기록을 남기는 것 역시 가능함)")
public ResponseEntity<?> updateArchive(@PathVariable("id") final Long id, @RequestParam("type") final ArchiveType archiveType,
public ResponseEntity<?> updateArchive(@PathVariable("archiveId") final Long archiveId,
@Valid @RequestBody ArchiveUpdateRequestDto requestDto) {
ArchiveResponseDto responseDto = archiveService.updateArchive(id, archiveType, requestDto);
ArchiveResponseDto responseDto = archiveService.updateArchive(archiveId, requestDto);
return ResponseEntity.ok(responseDto);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public record UserArchiveResponseDto(
public record ArchiveWithType(
ArchiveType type, // EXCERPT, REVIEW
Object data, // ExcerptResponseDto, ReviewResponseDto
Long archiveId,
String title,
String author
) {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ public ArchiveResponseDto createArchive(ArchiveCreateRequestDto requestDto) {

// 조회
@Transactional(readOnly = true)
public ArchiveResponseDto getArchive(Long id, ArchiveType archiveType) {
Archive archive = findArchiveByType(id, archiveType);
public ArchiveResponseDto getArchive(Long archiveId) {
Archive archive = getArchiveById(archiveId);
UserBook userBook = getUserBookFromExcerptOrReview(archive);
// currentUser와 creatorUser 사이의 관계에 따른 response 필터링
Long currentUserId = userService.getCurrentUser().getUserId();
Expand Down Expand Up @@ -118,8 +118,8 @@ public ArchiveResponseDto getSharedArchive(Long id, ArchiveType archiveType) {
}

// 수정
public ArchiveResponseDto updateArchive(Long id, ArchiveType archiveType, ArchiveUpdateRequestDto requestDto) {
Archive archive = findArchiveByType(id, archiveType);
public ArchiveResponseDto updateArchive(Long archiveId, ArchiveUpdateRequestDto requestDto) {
Archive archive = getArchiveById(archiveId);
UserBook userBook = getUserBookFromExcerptOrReview(archive);
// 생성자 검증
userBookService.validateUserBookOwner(userBook);
Expand Down Expand Up @@ -210,9 +210,10 @@ public UserArchiveResponseDto getUserArchive(Long userId, ArchiveType archiveTyp
if (!userId.equals(currentUserId) && excerpt.getVisibility() != Visibility.PUBLIC) {
continue;
}
Long archiveId = findArchiveByType(excerpt.getExcerptId(), EXCERPT).getArchiveId();
String title = excerpt.getUserBook().getBookInfo().getTitle();
String author = excerpt.getUserBook().getBookInfo().getAuthor();
archiveList.add(new UserArchiveResponseDto.ArchiveWithType(EXCERPT, ExcerptResponseDto.from(excerpt), title, author));
archiveList.add(new UserArchiveResponseDto.ArchiveWithType(EXCERPT, ExcerptResponseDto.from(excerpt), archiveId, title, author));
}
}
// 리뷰 조회
Expand All @@ -222,9 +223,10 @@ public UserArchiveResponseDto getUserArchive(Long userId, ArchiveType archiveTyp
if (!userId.equals(currentUserId) && review.getVisibility() != Visibility.PUBLIC) {
continue;
}
Long archiveId = findArchiveByType(review.getReviewId(), REVIEW).getArchiveId();
String title = review.getUserBook().getBookInfo().getTitle();
String author = review.getUserBook().getBookInfo().getAuthor();
archiveList.add(new UserArchiveResponseDto.ArchiveWithType(REVIEW, ReviewResponseDto.from(review), title, author));
archiveList.add(new UserArchiveResponseDto.ArchiveWithType(REVIEW, ReviewResponseDto.from(review), archiveId,title, author));
}
}
// 데이터 합친 후 최신순 정렬
Expand Down

0 comments on commit 0e37608

Please sign in to comment.