Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ public interface BookOverview {
String getTitle();
String getAuthor();
String getCoverImageUrl();
String getGoogleCoverImageUrl();
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ public interface BookRepository extends JpaRepository<Book, Long> {
SELECT b.id AS id,
b.title AS title,
b.author AS author,
b.coverImageUrl AS coverImageUrl
b.coverImageUrl AS coverImageUrl,
b.googleCoverImageUrl As googleCoverImageUrl
FROM Book b
WHERE b.provider = :provider
AND (LOWER(b.author) LIKE LOWER(CONCAT('%', :query, '%'))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
import ink.kindler.metasearch.rest.model.BookResponse;
import ink.kindler.metasearch.service.SearchService;
import org.springframework.http.ResponseEntity;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Objects;

@RestController
@RequestMapping("/v1/books")
Expand Down Expand Up @@ -43,7 +43,7 @@ private BookOverviewResponse convertToBookOverview(BookOverview bookOverview) {
bookOverview.getId(),
bookOverview.getTitle(),
bookOverview.getAuthor(),
bookOverview.getCoverImageUrl()
StringUtils.hasLength(bookOverview.getCoverImageUrl()) ? bookOverview.getCoverImageUrl() : bookOverview.getGoogleCoverImageUrl()
);
}

Expand All @@ -52,7 +52,7 @@ private BookResponse convertToBookResponse(Book book) {
book.getId(),
book.getTitle(),
book.getAuthor(),
Objects.isNull(book.getCoverImageUrl()) ? book.getGoogleCoverImageUrl() : book.getCoverImageUrl(),
StringUtils.hasLength(book.getCoverImageUrl()) ? book.getCoverImageUrl() : book.getGoogleCoverImageUrl(),
book.getEpubUrl(),
book.getKoboUrl(),
book.getMobiUrl(),
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ standard-ebooks:

gutenberg-australia:
enabled: true
always-reindex: true
always-reindex: false
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import ink.kindler.metasearch.persistent.projection.BookOverview;
import ink.kindler.metasearch.service.SearchService;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.CsvSource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
import org.springframework.test.context.bean.override.mockito.MockitoBean;
Expand Down Expand Up @@ -79,8 +81,8 @@ class SearchControllerTest {
@Test
void shouldSearchBookByQuery() throws Exception {
when(searchService.search(Provider.STANDARD_EBOOKS, "Mark")).thenReturn(List.of(
stubBookOverview(1L, "The Adventures of Tom Sawyer", "Mark Twain"),
stubBookOverview(2L, "The Mark of Zorro", "Johnston McCulley")
stubBookOverview(1L, "The Adventures of Tom Sawyer", "Mark Twain", null, "https://coverimageurl.com"),
stubBookOverview(2L, "The Mark of Zorro", "Johnston McCulley", "https://coverimageurl.com", null)
));

mockMvc.perform(get("/v1/books/search")
Expand Down Expand Up @@ -110,9 +112,10 @@ void shouldSearchBookById() throws Exception {
.andExpect(content().json(BOOK_BY_ID_RESPONSE));
}

@Test
void shouldReturnBookWithGoogleCoverImageWhenActualCoverImageIsNotPresent() throws Exception {
when(searchService.findBookById(1L)).thenReturn(Optional.of(stubBook(null)));
@ParameterizedTest
@CsvSource(value = {"null","''"}, nullValues = "null")
void shouldReturnBookWithGoogleCoverImageWhenActualCoverImageIsNotPresent(String coverImage) throws Exception {
when(searchService.findBookById(1L)).thenReturn(Optional.of(stubBook(coverImage)));

mockMvc.perform(get("/v1/books/1"))
.andDo(print())
Expand Down Expand Up @@ -157,7 +160,7 @@ private BookSummary stubBookSummary(Book book) {
return bookSummary;
}

private BookOverview stubBookOverview(Long id, String title, String author) {
private BookOverview stubBookOverview(Long id, String title, String author, String coverImage, String googleCoverImage) {
return new BookOverview() {
@Override
public Long getId() {
Expand All @@ -176,7 +179,12 @@ public String getAuthor() {

@Override
public String getCoverImageUrl() {
return "https://coverimageurl.com";
return coverImage;
}

@Override
public String getGoogleCoverImageUrl() {
return googleCoverImage;
}
};
}
Expand Down