Skip to content

Commit

Permalink
feat : #142 도서 썸네일 이미지 수정 api 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
Yujin-nKim committed May 6, 2024
1 parent c411aa8 commit 66b1dd6
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,20 @@ public ResponseEntity<BaseResponse<Void>> updateBookPublisher(
new BaseResponse<Void>().message("도서 출판사 수정 요청이 정상적으로 처리되었습니다."));
}

/**
* 특정 도서의 썸네일을 수정
* @param bookId 수정할 도서의 식별자
* @param image 수정할 썸네일 이미지
* @return 200 OK, 성공 메세지
* @author Yujin-nKim(김유진)
*/
@PutMapping("/books/{bookId}/book-thumbnail")
public ResponseEntity<BaseResponse<Void>> updateBookThumbnail(
@PathVariable Long bookId,
@RequestPart MultipartFile image) {

bookService.updateBookThumbnail(bookId, image);

return ResponseEntity.status(HttpStatus.OK).body(
new BaseResponse<Void>().message("도서 썸네일 수정 요청이 정상적으로 처리되었습니다."));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,11 @@
import org.springframework.data.jpa.repository.JpaRepository;

public interface BookThumbnailRepository extends JpaRepository<BookThumbnail, Long> {
/**
* 특정 도서에 대한 썸네일을 조회
* @param bookId 도서 식별자
* @return 해당 도서의 썸네일
* @author Yujin-nKim(김유진)
*/
BookThumbnail findByBookBookId(Long bookId);
}
22 changes: 22 additions & 0 deletions src/main/java/com/t3t/bookstoreapi/book/service/BookService.java
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,28 @@ public void updatePublisher(Long bookId, Long publisherId) {
bookRepository.save(book);
}

/**
* 특정 도서의 썸네일을 수정
* @param bookId 수정할 도서의 식별자
* @param image 수정할 썸네일 이미지
* @throws BookNotFoundException 도서를 찾을 수 없는 경우 발생
* @author Yujin-nKim(김유진)
*/
public void updateBookThumbnail(Long bookId, MultipartFile image) {
Book book = bookRepository.findByBookId(bookId).orElseThrow(BookNotFoundException::new);

BookThumbnail bookThumbnail = bookThumbnailRepository.findByBookBookId(bookId);
String fileName = bookThumbnail.getThumbnailImageUrl();
// Object Storage 기존 이미지 삭제 요청
fileUploadService.deleteObject("t3team", "book_thumbnails", fileName);
bookThumbnailRepository.delete(bookThumbnail);

String uploadFileName = generateUploadFileName(image);
// Object Storage 새로운 이미지 업로드 요청
fileUploadService.uploadObject("t3team", "book_thumbnails", uploadFileName, image);
bookThumbnailRepository.save(BookThumbnail.builder().book(book).thumbnailImageUrl(uploadFileName).build());
}

/**
* 업로드할 파일의 이름을 생성
*
Expand Down

0 comments on commit 66b1dd6

Please sign in to comment.