Skip to content

Commit

Permalink
feat: BookService 크롤링을 통한 책 저장 기능 추가 (#22)
Browse files Browse the repository at this point in the history
  • Loading branch information
jwooo committed Mar 23, 2024
1 parent e8d0024 commit b26843e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/main/java/com/jisungin/application/book/BookService.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -16,6 +17,7 @@
@RequiredArgsConstructor
public class BookService {

private final Crawler crawler;
private final BookRepository bookRepository;
private final ReviewRepository reviewRepository;

Expand All @@ -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()));
}

}
4 changes: 4 additions & 0 deletions src/main/java/com/jisungin/infra/crawler/CrawlingBook.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,8 @@ public static CrawlingBook of(String imageUrl, String content) {
.build();
}

public boolean isBlankContent() {
return this.content.isBlank();
}

}

0 comments on commit b26843e

Please sign in to comment.