Skip to content

Commit

Permalink
refactor: imageUrl 필드 추가로 인한 수정 (#22)
Browse files Browse the repository at this point in the history
  • Loading branch information
jwooo committed Mar 23, 2024
1 parent aa5a04f commit cf4a8fc
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@ public class BookCreateRequest {
@NotBlank(message = "책 내용 입력은 필수 입니다.")
private String contents;

@NotBlank(message = "책 경로 입력은 필수 입니다.")
private String url;

@NotBlank(message = "책 isbn 입력은 필수 입니다.")
private String isbn;

Expand All @@ -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;
Expand All @@ -58,7 +54,6 @@ public BookCreateServiceRequest toServiceRequest() {
return BookCreateServiceRequest.builder()
.title(title)
.contents(contents)
.url(url)
.isbn(isbn)
.dateTime(convertToLocalDateTime(dateTime))
.authors(convertToString(authors))
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
}
Expand All @@ -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();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand All @@ -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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<TalkRoomQueryResponse> getTalkRooms(TalkRoomSearchServiceRequest search) {
Expand All @@ -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());
}

Expand Down
8 changes: 4 additions & 4 deletions src/main/java/com/jisungin/domain/book/Book.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ private List<TalkRoomQueryResponse> findTalkRoom(TalkRoomSearchServiceRequest se
talkRoom.title,
talkRoom.content,
book.title,
book.url.as("bookImage")
book.imageUrl.as("bookImage")
))
.from(talkRoom)
.join(talkRoom.user, user)
Expand Down

0 comments on commit cf4a8fc

Please sign in to comment.