Skip to content

Commit

Permalink
#39 - Fix: 내도서만 상세 정보조회 가능하도록 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
ahah525 committed Nov 10, 2022
1 parent 67d55ee commit ad7198d
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public ResponseEntity<RsData> list(@AuthenticationPrincipal MemberContext member
// 도서 상세 조회
@GetMapping("/{myBookId}")
public ResponseEntity<RsData> detail(@PathVariable long myBookId, @AuthenticationPrincipal MemberContext memberContext) {
MyBookDetailDto myBookDetailDto = myBookService.findByIdForDetail(myBookId);
MyBookDetailDto myBookDetailDto = myBookService.findByIdForDetail(myBookId, memberContext.getId());

return Ut.spring.responseEntityOf(
RsData.successOf(Ut.mapOf("myBook", myBookDetailDto))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,6 @@ public interface MyBookRepository extends JpaRepository<MyBook, Long> {
void deleteByProductIdAndOwnerId(Long productId, Long ownerId);

List<MyBook> findByOwner(Member owner);

Optional<MyBook> findByIdAndOwnerId(long myBookId, long ownerId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,15 @@ public List<MyBookDto> findAllByOwner(Member owner) {
return myBookDtos;
}

public MyBook findById(long id) {
return myBookRepository.findById(id).orElseThrow(() -> {
throw new MyBookNotFoundException("");
public MyBook findByIdAndOwnerId(long myBookId, long ownerId) {
return myBookRepository.findByIdAndOwnerId(myBookId, ownerId).orElseThrow(() -> {
throw new MyBookNotFoundException("해당 상품 구매 이력이 존재하지 않습니다.");
});
}

public MyBookDetailDto findByIdForDetail(long id) {
MyBook myBook = findById(id);
public MyBookDetailDto findByIdForDetail(long myBookId, long ownerId) {
// 본인이 소유한 도서로 조회
MyBook myBook = findByIdAndOwnerId(myBookId, ownerId);

PostKeyword postKeyword = myBook.getProduct().getPostKeyword();
Member author = myBook.getProduct().getAuthor();
Expand All @@ -92,7 +93,6 @@ public MyBookDetailDto findByIdForDetail(long id) {
.map(postHashTag -> postHashTag.getPost())
.collect(Collectors.toList());

// 본인이 소유한 도서인지 검증
return MyBookDetailDto.toDto(myBook, posts);
}
}

0 comments on commit ad7198d

Please sign in to comment.