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)