mirror of
https://github.com/booklore-app/booklore.git
synced 2026-02-18 00:17:53 +01:00
Checkpoint
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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));
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user