Checkpoint

This commit is contained in:
aditya.chandel
2024-12-15 22:41:13 -07:00
parent 0aa1c1b923
commit 767c6604e8
51 changed files with 297 additions and 212 deletions

View File

@@ -2,6 +2,7 @@ package com.adityachandel.booklore.controller;
import com.adityachandel.booklore.model.dto.BookDTO;
import com.adityachandel.booklore.model.dto.BookViewerSettingDTO;
import com.adityachandel.booklore.model.dto.BookWithNeighborsDTO;
import com.adityachandel.booklore.model.dto.response.GoogleBooksMetadata;
import com.adityachandel.booklore.model.dto.request.SetMetadataRequest;
import com.adityachandel.booklore.service.BooksService;

View File

@@ -1,8 +1,10 @@
package com.adityachandel.booklore.controller;
import com.adityachandel.booklore.model.dto.BookDTO;
import com.adityachandel.booklore.model.dto.BookWithNeighborsDTO;
import com.adityachandel.booklore.model.dto.LibraryDTO;
import com.adityachandel.booklore.model.dto.request.CreateLibraryRequest;
import com.adityachandel.booklore.service.BooksService;
import com.adityachandel.booklore.service.LibraryService;
import jakarta.validation.constraints.Max;
import jakarta.validation.constraints.Min;
@@ -19,6 +21,7 @@ import org.springframework.web.servlet.mvc.method.annotation.SseEmitter;
public class LibraryController {
private LibraryService libraryService;
private BooksService booksService;
@PostMapping
public ResponseEntity<LibraryDTO> createLibraryNew(@RequestBody CreateLibraryRequest request) {
@@ -46,6 +49,11 @@ public class LibraryController {
return ResponseEntity.ok(libraryService.getLibraries(page, size));
}
@GetMapping("/{libraryId}/book/{bookId}/withNeighbors")
public ResponseEntity<BookWithNeighborsDTO> getBookWithNeighbours(@PathVariable long libraryId, @PathVariable long bookId) {
return ResponseEntity.ok(booksService.getBookWithNeighbours(libraryId, bookId));
}
@GetMapping("/{libraryId}/book/{bookId}")
public ResponseEntity<BookDTO> getBook(@PathVariable long libraryId, @PathVariable long bookId) {
return ResponseEntity.ok(libraryService.getBook(libraryId, bookId));

View File

@@ -0,0 +1,12 @@
package com.adityachandel.booklore.model.dto;
import lombok.Builder;
import lombok.Data;
@Builder
@Data
public class BookWithNeighborsDTO {
private BookDTO currentBook;
private Long previousBookId;
private Long nextBookId;
}

View File

@@ -27,5 +27,9 @@ public interface BookRepository extends JpaRepository<Book, Long>, JpaSpecificat
Page<Book> findByLastReadTimeIsNotNull(Pageable pageable);
Page<Book> findByAddedOnIsNotNull(Pageable pageable);
Optional<Book> findFirstByLibraryIdAndIdLessThanOrderByIdDesc(Long libraryId, Long currentBookId);
Optional<Book> findFirstByLibraryIdAndIdGreaterThanOrderByIdAsc(Long libraryId, Long currentBookId);
}

View File

@@ -2,6 +2,7 @@ package com.adityachandel.booklore.service;
import com.adityachandel.booklore.config.AppProperties;
import com.adityachandel.booklore.model.dto.BookDTO;
import com.adityachandel.booklore.model.dto.BookWithNeighborsDTO;
import com.adityachandel.booklore.model.dto.response.GoogleBooksMetadata;
import com.adityachandel.booklore.model.dto.BookViewerSettingDTO;
import com.adityachandel.booklore.model.dto.request.SetMetadataRequest;
@@ -47,6 +48,7 @@ public class BooksService {
private final BookMetadataRepository metadataRepository;
private final AuthorRepository authorRepository;
private final CategoryRepository categoryRepository;
private final LibraryRepository libraryRepository;
public BookDTO getBook(long bookId) {
@@ -210,4 +212,17 @@ public class BooksService {
return fileName.substring(0, dotIndex);
}
}
public BookWithNeighborsDTO getBookWithNeighbours(long libraryId, long bookId) {
libraryRepository.findById(libraryId).orElseThrow(() -> ErrorCode.LIBRARY_NOT_FOUND.createException(libraryId));
Book book = bookRepository.findById(bookId).orElseThrow(() -> ErrorCode.BOOK_NOT_FOUND.createException(bookId));
Book previousBook = bookRepository.findFirstByLibraryIdAndIdLessThanOrderByIdDesc(libraryId, bookId).orElse(null);
Book nextBook = bookRepository.findFirstByLibraryIdAndIdGreaterThanOrderByIdAsc(libraryId, bookId).orElse(null);
return BookWithNeighborsDTO.builder()
.currentBook(BookTransformer.convertToBookDTO(book))
.previousBookId(previousBook != null ? previousBook.getId() : null)
.nextBookId(nextBook != null ? nextBook.getId() : null)
.build();
}
}

View File

@@ -73,7 +73,7 @@ public class PdfFileProcessor implements FileProcessor {
}
}
generateCoverImage(bookFile, new File(appProperties.getPathConfig() + "/thumbs"), document);
} catch (IOException e) {
} catch (Exception e) {
log.error("Error while processing file {}", libraryFile.getFilePath(), e);
return FileProcessResult.builder()
.libraryFile(libraryFile)