From cf4a8fcc277b6c47889eb6b925572407115d9136 Mon Sep 17 00:00:00 2001 From: jwooo Date: Sat, 23 Mar 2024 19:27:14 +0900 Subject: [PATCH 1/3] =?UTF-8?q?refactor:=20imageUrl=20=ED=95=84=EB=93=9C?= =?UTF-8?q?=20=EC=B6=94=EA=B0=80=EB=A1=9C=20=EC=9D=B8=ED=95=9C=20=EC=88=98?= =?UTF-8?q?=EC=A0=95=20(#22)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/book/request/BookCreateRequest.java | 7 +----- .../request/BookCreateServiceRequest.java | 16 +++++++++----- .../book/response/BookResponse.java | 22 +++++++++++++++---- .../application/talkroom/TalkRoomService.java | 4 ++-- .../java/com/jisungin/domain/book/Book.java | 8 +++---- .../repository/TalkRoomRepositoryImpl.java | 2 +- 6 files changed, 37 insertions(+), 22 deletions(-) diff --git a/src/main/java/com/jisungin/api/book/request/BookCreateRequest.java b/src/main/java/com/jisungin/api/book/request/BookCreateRequest.java index 5bb2698..5cc3cfd 100644 --- a/src/main/java/com/jisungin/api/book/request/BookCreateRequest.java +++ b/src/main/java/com/jisungin/api/book/request/BookCreateRequest.java @@ -22,9 +22,6 @@ public class BookCreateRequest { @NotBlank(message = "책 내용 입력은 필수 입니다.") private String contents; - @NotBlank(message = "책 경로 입력은 필수 입니다.") - private String url; - @NotBlank(message = "책 isbn 입력은 필수 입니다.") private String isbn; @@ -42,11 +39,10 @@ public class BookCreateRequest { private String thumbnail; @Builder - private BookCreateRequest(String title, String contents, String url, String isbn, String dateTime, String[] authors, + private BookCreateRequest(String title, String contents, String isbn, String dateTime, String[] authors, String publisher, String thumbnail) { this.title = title; this.contents = contents; - this.url = url; this.isbn = isbn; this.dateTime = dateTime; this.authors = authors; @@ -58,7 +54,6 @@ public BookCreateServiceRequest toServiceRequest() { return BookCreateServiceRequest.builder() .title(title) .contents(contents) - .url(url) .isbn(isbn) .dateTime(convertToLocalDateTime(dateTime)) .authors(convertToString(authors)) diff --git a/src/main/java/com/jisungin/application/book/request/BookCreateServiceRequest.java b/src/main/java/com/jisungin/application/book/request/BookCreateServiceRequest.java index 9809b5f..b2a2976 100644 --- a/src/main/java/com/jisungin/application/book/request/BookCreateServiceRequest.java +++ b/src/main/java/com/jisungin/application/book/request/BookCreateServiceRequest.java @@ -1,6 +1,7 @@ package com.jisungin.application.book.request; import com.jisungin.domain.book.Book; +import com.jisungin.infra.crawler.CrawlingBook; import java.time.LocalDateTime; import lombok.Builder; import lombok.Getter; @@ -12,22 +13,22 @@ public class BookCreateServiceRequest { private String title; private String contents; - private String url; private String isbn; private String authors; private String publisher; + private String imageUrl; private String thumbnail; private LocalDateTime dateTime; @Builder - private BookCreateServiceRequest(String title, String contents, String url, String isbn, String authors, - String publisher, String thumbnail, LocalDateTime dateTime) { + private BookCreateServiceRequest(String title, String contents, String isbn, String authors, String publisher, + String imageUrl, String thumbnail, LocalDateTime dateTime) { this.title = title; this.contents = contents; - this.url = url; this.isbn = isbn; this.authors = authors; this.publisher = publisher; + this.imageUrl = imageUrl; this.thumbnail = thumbnail; this.dateTime = dateTime; } @@ -36,13 +37,18 @@ public Book toEntity() { return Book.builder() .title(title) .content(contents) - .url(url) .isbn(isbn) .dateTime(dateTime) .authors(authors) .publisher(publisher) .thumbnail(thumbnail) + .imageUrl(imageUrl) .build(); } + public void addCrawlingData(CrawlingBook crawlingBook) { + this.imageUrl = crawlingBook.getImageUrl(); + this.contents = crawlingBook.isBlankContent() ? this.contents : crawlingBook.getContent(); + } + } diff --git a/src/main/java/com/jisungin/application/book/response/BookResponse.java b/src/main/java/com/jisungin/application/book/response/BookResponse.java index aa91853..891fccc 100644 --- a/src/main/java/com/jisungin/application/book/response/BookResponse.java +++ b/src/main/java/com/jisungin/application/book/response/BookResponse.java @@ -14,26 +14,40 @@ public class BookResponse { private String content; private String isbn; private String publisher; - private String url; + private String imageUrl; private String thumbnail; private String[] authors; private Double ratingAverage; private LocalDateTime dateTime; @Builder - private BookResponse(String title, String content, String isbn, String publisher, String url, String thumbnail, + private BookResponse(String title, String content, String isbn, String publisher, String thumbnail, String imageUrl, String authors, Double ratingAverage, LocalDateTime dateTime) { this.title = title; this.content = content; this.isbn = isbn; this.publisher = publisher; - this.url = url; + this.imageUrl = imageUrl; this.thumbnail = thumbnail; this.authors = convertAuthorsToString(authors); this.ratingAverage = parseRatingAverage(ratingAverage); this.dateTime = dateTime; } + public static BookResponse of(Book book) { + return BookResponse.builder() + .title(book.getTitle()) + .content(book.getContent()) + .authors(book.getAuthors()) + .isbn(book.getIsbn()) + .publisher(book.getPublisher()) + .dateTime(book.getDateTime()) + .thumbnail(book.getThumbnail()) + .imageUrl(book.getImageUrl()) + .ratingAverage(0.0) + .build(); + } + public static BookResponse of(Book book, Double ratingAverage) { return BookResponse.builder() .title(book.getTitle()) @@ -42,8 +56,8 @@ public static BookResponse of(Book book, Double ratingAverage) { .isbn(book.getIsbn()) .publisher(book.getPublisher()) .dateTime(book.getDateTime()) - .url(book.getUrl()) .thumbnail(book.getThumbnail()) + .imageUrl(book.getImageUrl()) .ratingAverage(ratingAverage) .build(); } diff --git a/src/main/java/com/jisungin/application/talkroom/TalkRoomService.java b/src/main/java/com/jisungin/application/talkroom/TalkRoomService.java index ed15535..6879510 100644 --- a/src/main/java/com/jisungin/application/talkroom/TalkRoomService.java +++ b/src/main/java/com/jisungin/application/talkroom/TalkRoomService.java @@ -52,7 +52,7 @@ public TalkRoomResponse createTalkRoom(TalkRoomCreateServiceRequest request, Str readingStatus.stream().map(status -> TalkRoomRole.roleCreate(talkRoom, status)) .forEach(talkRoomRoleRepository::save); - return TalkRoomResponse.of(user.getName(), talkRoom, readingStatus, book.getUrl(), book.getTitle()); + return TalkRoomResponse.of(user.getName(), talkRoom, readingStatus, book.getImageUrl(), book.getTitle()); } public PageResponse getTalkRooms(TalkRoomSearchServiceRequest search) { @@ -79,7 +79,7 @@ public TalkRoomResponse editTalkRoom(TalkRoomEditServiceRequest request, String readingStatus.stream().map(status -> TalkRoomRole.roleCreate(talkRoom, status)) .forEach(talkRoomRoleRepository::save); - return TalkRoomResponse.of(user.getName(), talkRoom, readingStatus, talkRoom.getBook().getUrl(), + return TalkRoomResponse.of(user.getName(), talkRoom, readingStatus, talkRoom.getBook().getImageUrl(), talkRoom.getBook().getTitle()); } diff --git a/src/main/java/com/jisungin/domain/book/Book.java b/src/main/java/com/jisungin/domain/book/Book.java index 3e4beaf..347fee5 100644 --- a/src/main/java/com/jisungin/domain/book/Book.java +++ b/src/main/java/com/jisungin/domain/book/Book.java @@ -33,8 +33,8 @@ public class Book extends BaseEntity { @Column(name = "book_publisher") private String publisher; - @Column(name = "book_url") - private String url; + @Column(name = "book_image") + private String imageUrl; @Column(name = "book_thumbnail") private String thumbnail; @@ -44,14 +44,14 @@ public class Book extends BaseEntity { @Builder - private Book(String isbn, String title, String content, String authors, String publisher, String url, + private Book(String isbn, String title, String content, String authors, String publisher, String imageUrl, String thumbnail, LocalDateTime dateTime) { this.isbn = isbn; this.title = title; this.content = content; this.authors = authors; this.publisher = publisher; - this.url = url; + this.imageUrl = imageUrl; this.thumbnail = thumbnail; this.dateTime = dateTime; } diff --git a/src/main/java/com/jisungin/domain/talkroom/repository/TalkRoomRepositoryImpl.java b/src/main/java/com/jisungin/domain/talkroom/repository/TalkRoomRepositoryImpl.java index 5e97e1f..ce4ecde 100644 --- a/src/main/java/com/jisungin/domain/talkroom/repository/TalkRoomRepositoryImpl.java +++ b/src/main/java/com/jisungin/domain/talkroom/repository/TalkRoomRepositoryImpl.java @@ -80,7 +80,7 @@ private List findTalkRoom(TalkRoomSearchServiceRequest se talkRoom.title, talkRoom.content, book.title, - book.url.as("bookImage") + book.imageUrl.as("bookImage") )) .from(talkRoom) .join(talkRoom.user, user) From e8d0024a3b06a8f1ab8829c0b3219fcaba7b693b Mon Sep 17 00:00:00 2001 From: jwooo Date: Sat, 23 Mar 2024 19:27:58 +0900 Subject: [PATCH 2/3] =?UTF-8?q?test:=20imageUrl=20=ED=95=84=EB=93=9C=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80=EB=A1=9C=20=EC=9D=B8=ED=95=9C=20=ED=85=8C?= =?UTF-8?q?=EC=8A=A4=ED=8A=B8=20=EC=BD=94=EB=93=9C=20=EC=88=98=EC=A0=95=20?= =?UTF-8?q?(#22)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../jisungin/api/book/BookControllerTest.java | 35 +------------------ .../api/talkroom/TalkRoomControllerTest.java | 2 +- .../service/talkroom/TalkRoomServiceTest.java | 2 +- .../TalkRoomRepositoryImplTest.java | 2 +- 4 files changed, 4 insertions(+), 37 deletions(-) diff --git a/src/test/java/com/jisungin/api/book/BookControllerTest.java b/src/test/java/com/jisungin/api/book/BookControllerTest.java index d888d6c..31b4cc4 100644 --- a/src/test/java/com/jisungin/api/book/BookControllerTest.java +++ b/src/test/java/com/jisungin/api/book/BookControllerTest.java @@ -77,7 +77,6 @@ public void createBook() throws Exception { BookCreateRequest request = BookCreateRequest.builder() .title("도서 정보") .contents("도서 내용") - .url("도서 URL") .isbn("도서 isbn") .dateTime("2024-03-15T00:00:00.000+09:00") .authors(new String[]{"도서 저자1", "도서 저자2"}) @@ -106,7 +105,6 @@ public void createBookWithDuplicateIsbn() throws Exception { BookCreateRequest request = BookCreateRequest.builder() .title("도서 정보") .contents("도서 내용") - .url("도서 URL") .isbn("도서 isbn") .dateTime("2024-03-15T00:00:00.000+09:00") .authors(new String[]{"도서 저자1", "도서 저자2"}) @@ -130,7 +128,6 @@ public void createBookWithNonTitle() throws Exception { // given BookCreateRequest request = BookCreateRequest.builder() .contents("도서 내용") - .url("도서 URL") .isbn("도서 isbn") .dateTime("2024-03-15T00:00:00.000+09:00") .authors(new String[]{"도서 저자1", "도서 저자2"}) @@ -154,7 +151,6 @@ public void createBookWithNonContents() throws Exception { // given BookCreateRequest request = BookCreateRequest.builder() .title("도서 정보") - .url("도서 URL") .isbn("도서 isbn") .dateTime("2024-03-15T00:00:00.000+09:00") .authors(new String[]{"도서 저자1", "도서 저자2"}) @@ -172,30 +168,6 @@ public void createBookWithNonContents() throws Exception { .andExpect(jsonPath("$.message").value("책 내용 입력은 필수 입니다.")); } - @Test - @DisplayName("신규 도서 등록 시 책 경로는 필수이어야 한다.") - public void createBookWithNonUrl() throws Exception { - // given - BookCreateRequest request = BookCreateRequest.builder() - .title("도서 정보") - .contents("도서 내용") - .isbn("도서 isbn") - .dateTime("2024-03-15T00:00:00.000+09:00") - .authors(new String[]{"도서 저자1", "도서 저자2"}) - .publisher("도서 출판사") - .thumbnail("도서 썸네일") - .build(); - - // when // then - mockMvc.perform(post("/v1/books") - .content(objectMapper.writeValueAsString(request)) - .contentType(APPLICATION_JSON)) - .andDo(print()) - .andExpect(status().isBadRequest()) - .andExpect(jsonPath("$.code").value("400")) - .andExpect(jsonPath("$.message").value("책 경로 입력은 필수 입니다.")); - } - @Test @DisplayName("신규 도서 등록 시 책 isbn 입력은 필수이어야 한다.") public void createBookWithNonIsbn() throws Exception { @@ -203,7 +175,6 @@ public void createBookWithNonIsbn() throws Exception { BookCreateRequest request = BookCreateRequest.builder() .title("도서 정보") .contents("도서 내용") - .url("도서 URL") .dateTime("2024-03-15T00:00:00.000+09:00") .authors(new String[]{"도서 저자1", "도서 저자2"}) .publisher("도서 출판사") @@ -227,7 +198,6 @@ public void createBookWithNonDateTime() throws Exception { BookCreateRequest request = BookCreateRequest.builder() .title("도서 정보") .contents("도서 내용") - .url("도서 URL") .isbn("도서 isbn") .authors(new String[]{"도서 저자1", "도서 저자2"}) .publisher("도서 출판사") @@ -251,7 +221,6 @@ public void createBookWithAuthors() throws Exception { BookCreateRequest request = BookCreateRequest.builder() .title("도서 정보") .contents("도서 내용") - .url("도서 URL") .isbn("도서 isbn") .dateTime("2024-03-15T00:00:00.000+09:00") .publisher("도서 출판사") @@ -275,7 +244,6 @@ public void createBookWithPublisher() throws Exception { BookCreateRequest request = BookCreateRequest.builder() .title("도서 정보") .contents("도서 내용") - .url("도서 URL") .isbn("도서 isbn") .dateTime("2024-03-15T00:00:00.000+09:00") .authors(new String[]{"도서 저자1", "도서 저자2"}) @@ -302,7 +270,6 @@ public void createBookWithThumbnail() throws Exception { BookCreateRequest request = BookCreateRequest.builder() .title("도서 정보") .contents("도서 내용") - .url("도서 URL") .isbn("도서 isbn") .dateTime("2024-03-15T00:00:00.000+09:00") .authors(new String[]{"도서 저자1", "도서 저자2"}) @@ -323,7 +290,7 @@ private static Book create() { return Book.builder() .title("도서 정보") .content("도서 내용") - .url("도서 URL") + .imageUrl("도서 URL") .isbn("도서 isbn") .dateTime(LocalDateTime.now()) .authors("도서 저자1, 도서 저자2") diff --git a/src/test/java/com/jisungin/api/talkroom/TalkRoomControllerTest.java b/src/test/java/com/jisungin/api/talkroom/TalkRoomControllerTest.java index 722dd34..0d01f4d 100644 --- a/src/test/java/com/jisungin/api/talkroom/TalkRoomControllerTest.java +++ b/src/test/java/com/jisungin/api/talkroom/TalkRoomControllerTest.java @@ -479,7 +479,7 @@ private static Book createBook() { .isbn("11111") .publisher("publisher") .dateTime(LocalDateTime.now()) - .url("www") + .imageUrl("www") .build(); } diff --git a/src/test/java/com/jisungin/application/service/talkroom/TalkRoomServiceTest.java b/src/test/java/com/jisungin/application/service/talkroom/TalkRoomServiceTest.java index bb232e7..5ae0ee9 100644 --- a/src/test/java/com/jisungin/application/service/talkroom/TalkRoomServiceTest.java +++ b/src/test/java/com/jisungin/application/service/talkroom/TalkRoomServiceTest.java @@ -474,7 +474,7 @@ private static Book createBook() { .isbn("11111") .publisher("publisher") .dateTime(LocalDateTime.now()) - .url("www") + .imageUrl("www") .build(); } diff --git a/src/test/java/com/jisungin/domain/talkroom/repository/TalkRoomRepositoryImplTest.java b/src/test/java/com/jisungin/domain/talkroom/repository/TalkRoomRepositoryImplTest.java index 127f8e4..c3e848b 100644 --- a/src/test/java/com/jisungin/domain/talkroom/repository/TalkRoomRepositoryImplTest.java +++ b/src/test/java/com/jisungin/domain/talkroom/repository/TalkRoomRepositoryImplTest.java @@ -131,7 +131,7 @@ private static Book createBook() { .isbn("11111") .publisher("publisher") .dateTime(LocalDateTime.now()) - .url("www") + .imageUrl("www") .build(); } From b26843e99936961d662d8043c216aef571685359 Mon Sep 17 00:00:00 2001 From: jwooo Date: Sat, 23 Mar 2024 19:30:09 +0900 Subject: [PATCH 3/3] =?UTF-8?q?feat:=20BookService=20=ED=81=AC=EB=A1=A4?= =?UTF-8?q?=EB=A7=81=EC=9D=84=20=ED=86=B5=ED=95=9C=20=EC=B1=85=20=EC=A0=80?= =?UTF-8?q?=EC=9E=A5=20=EA=B8=B0=EB=8A=A5=20=EC=B6=94=EA=B0=80=20(#22)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/jisungin/application/book/BookService.java | 6 +++++- src/main/java/com/jisungin/infra/crawler/CrawlingBook.java | 4 ++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/jisungin/application/book/BookService.java b/src/main/java/com/jisungin/application/book/BookService.java index cb2a406..e30a7cb 100644 --- a/src/main/java/com/jisungin/application/book/BookService.java +++ b/src/main/java/com/jisungin/application/book/BookService.java @@ -7,6 +7,7 @@ import com.jisungin.domain.review.repository.ReviewRepository; import com.jisungin.exception.BusinessException; import com.jisungin.exception.ErrorCode; +import com.jisungin.infra.crawler.Crawler; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -16,6 +17,7 @@ @RequiredArgsConstructor public class BookService { + private final Crawler crawler; private final BookRepository bookRepository; private final ReviewRepository reviewRepository; @@ -34,7 +36,9 @@ public BookResponse createBook(BookCreateServiceRequest request) { throw new BusinessException(ErrorCode.BOOK_ALREADY_EXIST); } - return BookResponse.of(bookRepository.save(request.toEntity()), 0.0); + request.addCrawlingData(crawler.crawlBook(request.getIsbn())); + + return BookResponse.of(bookRepository.save(request.toEntity())); } } diff --git a/src/main/java/com/jisungin/infra/crawler/CrawlingBook.java b/src/main/java/com/jisungin/infra/crawler/CrawlingBook.java index cb5d518..9de8f88 100644 --- a/src/main/java/com/jisungin/infra/crawler/CrawlingBook.java +++ b/src/main/java/com/jisungin/infra/crawler/CrawlingBook.java @@ -22,4 +22,8 @@ public static CrawlingBook of(String imageUrl, String content) { .build(); } + public boolean isBlankContent() { + return this.content.isBlank(); + } + }