Rename book repo
This commit is contained in:
+1
-1
@@ -15,7 +15,7 @@ import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
@Repository
|
||||
public interface BookEntityRepository extends JpaRepository<BookEntity, Long>, JpaSpecificationExecutor<BookEntity> {
|
||||
public interface BookRepository extends JpaRepository<BookEntity, Long>, JpaSpecificationExecutor<BookEntity> {
|
||||
|
||||
Optional<BookEntity> findByFileName(String fileName);
|
||||
|
||||
@@ -5,7 +5,7 @@ import com.adityachandel.booklore.model.dto.Author;
|
||||
import com.adityachandel.booklore.model.entity.AuthorEntity;
|
||||
import com.adityachandel.booklore.exception.ApiError;
|
||||
import com.adityachandel.booklore.repository.AuthorRepository;
|
||||
import com.adityachandel.booklore.repository.BookEntityRepository;
|
||||
import com.adityachandel.booklore.repository.BookRepository;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@@ -16,7 +16,7 @@ import java.util.List;
|
||||
public class AuthorService {
|
||||
|
||||
private final AuthorRepository authorRepository;
|
||||
private final BookEntityRepository bookEntityRepository;
|
||||
private final BookRepository bookRepository;
|
||||
private final AuthorMapper authorMapper;
|
||||
|
||||
public Author getAuthorById(Long id) {
|
||||
@@ -25,7 +25,7 @@ public class AuthorService {
|
||||
}
|
||||
|
||||
public List<Author> getAuthorsByBookId(Long bookId) {
|
||||
bookEntityRepository.findById(bookId).orElseThrow(() -> ApiError.BOOK_NOT_FOUND.createException(bookId));
|
||||
bookRepository.findById(bookId).orElseThrow(() -> ApiError.BOOK_NOT_FOUND.createException(bookId));
|
||||
List<AuthorEntity> authorEntities = authorRepository.findAuthorsByBookId(bookId);
|
||||
return authorEntities.stream().map(authorMapper::toAuthor).toList();
|
||||
}
|
||||
|
||||
+3
-3
@@ -7,7 +7,7 @@ import com.adityachandel.booklore.model.entity.BookMetadataEntity;
|
||||
import com.adityachandel.booklore.model.entity.BookViewerSettingEntity;
|
||||
import com.adityachandel.booklore.repository.AuthorRepository;
|
||||
import com.adityachandel.booklore.repository.BookMetadataRepository;
|
||||
import com.adityachandel.booklore.repository.BookEntityRepository;
|
||||
import com.adityachandel.booklore.repository.BookRepository;
|
||||
import com.adityachandel.booklore.repository.BookViewerSettingRepository;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
@@ -22,7 +22,7 @@ import java.util.Set;
|
||||
public class BookCreatorService {
|
||||
|
||||
private AuthorRepository authorRepository;
|
||||
private BookEntityRepository bookEntityRepository;
|
||||
private BookRepository bookRepository;
|
||||
private BookMetadataRepository bookMetadataRepository;
|
||||
private BookViewerSettingRepository bookViewerSettingRepository;
|
||||
|
||||
@@ -66,7 +66,7 @@ public class BookCreatorService {
|
||||
if (bookEntity.getMetadata().getAuthors() != null && !bookEntity.getMetadata().getAuthors().isEmpty()) {
|
||||
authorRepository.saveAll(bookEntity.getMetadata().getAuthors());
|
||||
}
|
||||
bookEntityRepository.save(bookEntity);
|
||||
bookRepository.save(bookEntity);
|
||||
bookMetadataRepository.save(bookEntity.getMetadata());
|
||||
bookViewerSettingRepository.save(bookEntity.getViewerSetting());
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ import com.adityachandel.booklore.model.dto.BookWithNeighbors;
|
||||
import com.adityachandel.booklore.model.entity.BookEntity;
|
||||
import com.adityachandel.booklore.model.entity.BookViewerSettingEntity;
|
||||
import com.adityachandel.booklore.model.entity.ShelfEntity;
|
||||
import com.adityachandel.booklore.repository.BookEntityRepository;
|
||||
import com.adityachandel.booklore.repository.BookRepository;
|
||||
import com.adityachandel.booklore.repository.BookViewerSettingRepository;
|
||||
import com.adityachandel.booklore.repository.LibraryRepository;
|
||||
import com.adityachandel.booklore.repository.ShelfRepository;
|
||||
@@ -35,7 +35,7 @@ import java.util.stream.Collectors;
|
||||
@Service
|
||||
public class BooksService {
|
||||
|
||||
private final BookEntityRepository bookEntityRepository;
|
||||
private final BookRepository bookRepository;
|
||||
private final BookViewerSettingRepository bookViewerSettingRepository;
|
||||
private final LibraryRepository libraryRepository;
|
||||
private final ShelfRepository shelfRepository;
|
||||
@@ -45,7 +45,7 @@ public class BooksService {
|
||||
|
||||
|
||||
public Book getBook(long bookId, boolean withDescription) {
|
||||
BookEntity bookEntity = bookEntityRepository.findById(bookId).orElseThrow(() -> ApiError.BOOK_NOT_FOUND.createException(bookId));
|
||||
BookEntity bookEntity = bookRepository.findById(bookId).orElseThrow(() -> ApiError.BOOK_NOT_FOUND.createException(bookId));
|
||||
Book book = bookMapper.toBook(bookEntity);
|
||||
if (!withDescription) {
|
||||
book.getMetadata().setDescription(null);
|
||||
@@ -54,7 +54,7 @@ public class BooksService {
|
||||
}
|
||||
|
||||
public List<Book> getBooks(boolean withDescription) {
|
||||
return bookEntityRepository.findAll().stream()
|
||||
return bookRepository.findAll().stream()
|
||||
.map(bookEntity -> bookMapper.toBookWithDescription(bookEntity, withDescription))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
@@ -69,7 +69,7 @@ public class BooksService {
|
||||
}
|
||||
|
||||
public ResponseEntity<byte[]> getBookData(long bookId) throws IOException {
|
||||
BookEntity bookEntity = bookEntityRepository.findById(bookId).orElseThrow(() -> ApiError.BOOK_NOT_FOUND.createException(bookId));
|
||||
BookEntity bookEntity = bookRepository.findById(bookId).orElseThrow(() -> ApiError.BOOK_NOT_FOUND.createException(bookId));
|
||||
byte[] pdfBytes = Files.readAllBytes(new File(bookEntity.getPath()).toPath());
|
||||
return ResponseEntity.ok()
|
||||
.header(HttpHeaders.CONTENT_TYPE, "application/pdf")
|
||||
@@ -77,7 +77,7 @@ public class BooksService {
|
||||
}
|
||||
|
||||
public List<Book> search(String title) {
|
||||
List<BookEntity> bookEntities = bookEntityRepository.findByTitleContainingIgnoreCase(title);
|
||||
List<BookEntity> bookEntities = bookRepository.findByTitleContainingIgnoreCase(title);
|
||||
return bookEntities.stream().map(bookMapper::toBook).toList();
|
||||
}
|
||||
|
||||
@@ -87,16 +87,16 @@ public class BooksService {
|
||||
}
|
||||
|
||||
public Book updateLastReadTime(long bookId) {
|
||||
BookEntity bookEntity = bookEntityRepository.findById(bookId).orElseThrow(() -> ApiError.BOOK_NOT_FOUND.createException(bookId));
|
||||
BookEntity bookEntity = bookRepository.findById(bookId).orElseThrow(() -> ApiError.BOOK_NOT_FOUND.createException(bookId));
|
||||
bookEntity.setLastReadTime(Instant.now());
|
||||
return bookMapper.toBook(bookEntityRepository.save(bookEntity));
|
||||
return bookMapper.toBook(bookRepository.save(bookEntity));
|
||||
}
|
||||
|
||||
public BookWithNeighbors getBookWithNeighbours(long libraryId, long bookId) {
|
||||
libraryRepository.findById(libraryId).orElseThrow(() -> ApiError.LIBRARY_NOT_FOUND.createException(libraryId));
|
||||
BookEntity bookEntity = bookEntityRepository.findById(bookId).orElseThrow(() -> ApiError.BOOK_NOT_FOUND.createException(bookId));
|
||||
BookEntity previousBookEntity = bookEntityRepository.findFirstByLibraryIdAndIdLessThanOrderByIdDesc(libraryId, bookId).orElse(null);
|
||||
BookEntity nextBookEntity = bookEntityRepository.findFirstByLibraryIdAndIdGreaterThanOrderByIdAsc(libraryId, bookId).orElse(null);
|
||||
BookEntity bookEntity = bookRepository.findById(bookId).orElseThrow(() -> ApiError.BOOK_NOT_FOUND.createException(bookId));
|
||||
BookEntity previousBookEntity = bookRepository.findFirstByLibraryIdAndIdLessThanOrderByIdDesc(libraryId, bookId).orElse(null);
|
||||
BookEntity nextBookEntity = bookRepository.findFirstByLibraryIdAndIdGreaterThanOrderByIdAsc(libraryId, bookId).orElse(null);
|
||||
return BookWithNeighbors.builder()
|
||||
.currentBook(bookMapper.toBook(bookEntity))
|
||||
.previousBookId(previousBookEntity != null ? previousBookEntity.getId() : null)
|
||||
@@ -106,7 +106,7 @@ public class BooksService {
|
||||
|
||||
@Transactional
|
||||
public List<Book> assignShelvesToBooks(Set<Long> bookIds, Set<Long> shelfIdsToAssign, Set<Long> shelfIdsToUnassign) {
|
||||
List<BookEntity> bookEntities = bookEntityRepository.findAllById(bookIds);
|
||||
List<BookEntity> bookEntities = bookRepository.findAllById(bookIds);
|
||||
List<ShelfEntity> shelvesToAssign = shelfRepository.findAllById(shelfIdsToAssign);
|
||||
List<ShelfEntity> shelvesToUnassign = shelfRepository.findAllById(shelfIdsToUnassign);
|
||||
for (BookEntity bookEntity : bookEntities) {
|
||||
@@ -121,14 +121,14 @@ public class BooksService {
|
||||
shelf.getBookEntities().add(bookEntity);
|
||||
}
|
||||
});
|
||||
bookEntityRepository.save(bookEntity);
|
||||
bookRepository.save(bookEntity);
|
||||
shelfRepository.saveAll(shelvesToAssign);
|
||||
}
|
||||
return bookEntities.stream().map(bookMapper::toBook).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public Resource getBookCover(long bookId) {
|
||||
BookEntity bookEntity = bookEntityRepository.findById(bookId).orElseThrow(() -> ApiError.BOOK_NOT_FOUND.createException(bookId));
|
||||
BookEntity bookEntity = bookRepository.findById(bookId).orElseThrow(() -> ApiError.BOOK_NOT_FOUND.createException(bookId));
|
||||
return fileService.getBookCover(bookEntity.getMetadata().getThumbnail());
|
||||
}
|
||||
}
|
||||
+3
-3
@@ -8,7 +8,7 @@ import com.adityachandel.booklore.model.entity.LibraryEntity;
|
||||
import com.adityachandel.booklore.model.enums.BookFileType;
|
||||
import com.adityachandel.booklore.model.stomp.BookNotification;
|
||||
import com.adityachandel.booklore.model.stomp.Topic;
|
||||
import com.adityachandel.booklore.repository.BookEntityRepository;
|
||||
import com.adityachandel.booklore.repository.BookRepository;
|
||||
import com.adityachandel.booklore.repository.LibraryRepository;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
@@ -35,7 +35,7 @@ public class LibraryProcessingService {
|
||||
private final LibraryRepository libraryRepository;
|
||||
private final NotificationService notificationService;
|
||||
private final PdfFileProcessor pdfFileProcessor;
|
||||
private final BookEntityRepository bookEntityRepository;
|
||||
private final BookRepository bookRepository;
|
||||
|
||||
|
||||
@Transactional
|
||||
@@ -60,7 +60,7 @@ public class LibraryProcessingService {
|
||||
protected void deleteRemovedBooks(List<BookEntity> removedBookEntities) {
|
||||
if (!removedBookEntities.isEmpty()) {
|
||||
Set<Long> bookIds = removedBookEntities.stream().map(BookEntity::getId).collect(Collectors.toSet());
|
||||
bookEntityRepository.deleteByIdIn(bookIds);
|
||||
bookRepository.deleteByIdIn(bookIds);
|
||||
BookNotification notification = BookNotification.builder().action(BOOKS_REMOVED).removedBookIds(bookIds).build();
|
||||
notificationService.sendMessage(Topic.BOOK, notification);
|
||||
log.info("Books removed: {}", bookIds);
|
||||
|
||||
@@ -9,7 +9,7 @@ import com.adityachandel.booklore.model.dto.Sort;
|
||||
import com.adityachandel.booklore.model.dto.request.CreateLibraryRequest;
|
||||
import com.adityachandel.booklore.model.entity.BookEntity;
|
||||
import com.adityachandel.booklore.model.entity.LibraryEntity;
|
||||
import com.adityachandel.booklore.repository.BookEntityRepository;
|
||||
import com.adityachandel.booklore.repository.BookRepository;
|
||||
import com.adityachandel.booklore.repository.LibraryRepository;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
@@ -25,7 +25,7 @@ import java.util.List;
|
||||
public class LibraryService {
|
||||
|
||||
private final LibraryRepository libraryRepository;
|
||||
private final BookEntityRepository bookEntityRepository;
|
||||
private final BookRepository bookRepository;
|
||||
private final LibraryProcessingService libraryProcessingService;
|
||||
private final BookMapper bookMapper;
|
||||
private final LibraryMapper libraryMapper;
|
||||
@@ -82,13 +82,13 @@ public class LibraryService {
|
||||
|
||||
public Book getBook(long libraryId, long bookId) {
|
||||
libraryRepository.findById(libraryId).orElseThrow(() -> ApiError.LIBRARY_NOT_FOUND.createException(libraryId));
|
||||
BookEntity bookEntity = bookEntityRepository.findBookByIdAndLibraryId(bookId, libraryId).orElseThrow(() -> ApiError.BOOK_NOT_FOUND.createException(bookId));
|
||||
BookEntity bookEntity = bookRepository.findBookByIdAndLibraryId(bookId, libraryId).orElseThrow(() -> ApiError.BOOK_NOT_FOUND.createException(bookId));
|
||||
return bookMapper.toBook(bookEntity);
|
||||
}
|
||||
|
||||
public List<Book> getBooks(long libraryId) {
|
||||
libraryRepository.findById(libraryId).orElseThrow(() -> ApiError.LIBRARY_NOT_FOUND.createException(libraryId));
|
||||
List<BookEntity> bookEntities = bookEntityRepository.findBooksByLibraryId(libraryId);
|
||||
List<BookEntity> bookEntities = bookRepository.findBooksByLibraryId(libraryId);
|
||||
return bookEntities.stream().map(bookMapper::toBook).toList();
|
||||
}
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ import com.adityachandel.booklore.model.LibraryFile;
|
||||
import com.adityachandel.booklore.model.dto.Book;
|
||||
import com.adityachandel.booklore.model.entity.BookEntity;
|
||||
import com.adityachandel.booklore.model.entity.BookMetadataEntity;
|
||||
import com.adityachandel.booklore.repository.BookEntityRepository;
|
||||
import com.adityachandel.booklore.repository.BookRepository;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.pdfbox.Loader;
|
||||
@@ -33,7 +33,7 @@ import java.util.stream.Collectors;
|
||||
@AllArgsConstructor
|
||||
public class PdfFileProcessor implements FileProcessor {
|
||||
|
||||
private BookEntityRepository bookEntityRepository;
|
||||
private BookRepository bookRepository;
|
||||
private BookCreatorService bookCreatorService;
|
||||
private AppProperties appProperties;
|
||||
private BookMapper bookMapper;
|
||||
@@ -44,7 +44,7 @@ public class PdfFileProcessor implements FileProcessor {
|
||||
File bookFile = new File(libraryFile.getFilePath());
|
||||
String fileName = bookFile.getName();
|
||||
if (!forceProcess) {
|
||||
Optional<BookEntity> bookOptional = bookEntityRepository.findBookByFileNameAndLibraryId(fileName, libraryFile.getLibraryEntity().getId());
|
||||
Optional<BookEntity> bookOptional = bookRepository.findBookByFileNameAndLibraryId(fileName, libraryFile.getLibraryEntity().getId());
|
||||
return bookOptional
|
||||
.map(bookMapper::toBook)
|
||||
.orElseGet(() -> processNewFile(libraryFile));
|
||||
@@ -71,12 +71,12 @@ public class PdfFileProcessor implements FileProcessor {
|
||||
}
|
||||
}
|
||||
bookCreatorService.saveConnections(bookEntity);
|
||||
BookEntity saved = bookEntityRepository.save(bookEntity);
|
||||
BookEntity saved = bookRepository.save(bookEntity);
|
||||
boolean success = generateCoverImage(saved.getId(), new File(appProperties.getPathConfig() + "/thumbs"), document);
|
||||
if (success) {
|
||||
bookMetadataEntity.setThumbnail(appProperties.getPathConfig() + "/thumbs/" + bookEntity.getId() + "/f.jpg");
|
||||
}
|
||||
bookEntityRepository.flush();
|
||||
bookRepository.flush();
|
||||
} catch (Exception e) {
|
||||
log.error("Error while processing file {}, error: {}", libraryFile.getFilePath(), e.getMessage());
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ import com.adityachandel.booklore.model.dto.request.ShelfCreateRequest;
|
||||
import com.adityachandel.booklore.model.entity.BookEntity;
|
||||
import com.adityachandel.booklore.model.entity.ShelfEntity;
|
||||
import com.adityachandel.booklore.model.dto.Sort;
|
||||
import com.adityachandel.booklore.repository.BookEntityRepository;
|
||||
import com.adityachandel.booklore.repository.BookRepository;
|
||||
import com.adityachandel.booklore.repository.ShelfRepository;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
@@ -21,7 +21,7 @@ import java.util.List;
|
||||
public class ShelfService {
|
||||
|
||||
private final ShelfRepository shelfRepository;
|
||||
private final BookEntityRepository bookEntityRepository;
|
||||
private final BookRepository bookRepository;
|
||||
private final ShelfMapper shelfMapper;
|
||||
private final BookMapper bookMapper;
|
||||
|
||||
@@ -59,7 +59,7 @@ public class ShelfService {
|
||||
|
||||
public List<Book> getShelfBooks(Long shelfId) {
|
||||
shelfRepository.findById(shelfId).orElseThrow(() -> ApiError.SHELF_NOT_FOUND.createException(shelfId));
|
||||
List<BookEntity> bookEntities = bookEntityRepository.findByShelfId(shelfId);
|
||||
List<BookEntity> bookEntities = bookRepository.findByShelfId(shelfId);
|
||||
return bookEntities.stream()
|
||||
.map(bookMapper::toBook)
|
||||
.toList();
|
||||
|
||||
+3
-3
@@ -31,7 +31,7 @@ import java.util.stream.Collectors;
|
||||
public class BookMetadataService {
|
||||
|
||||
private AmazonBookParser amazonBookParser;
|
||||
private BookEntityRepository bookEntityRepository;
|
||||
private BookRepository bookRepository;
|
||||
private LibraryRepository libraryRepository;
|
||||
private AuthorRepository authorRepository;
|
||||
private BookMetadataRepository bookMetadataRepository;
|
||||
@@ -45,7 +45,7 @@ public class BookMetadataService {
|
||||
|
||||
|
||||
public List<FetchedBookMetadata> fetchMetadataList(long bookId, FetchMetadataRequest request) {
|
||||
BookEntity bookEntity = bookEntityRepository.findById(bookId).orElseThrow(() -> ApiError.BOOK_NOT_FOUND.createException(bookId));
|
||||
BookEntity bookEntity = bookRepository.findById(bookId).orElseThrow(() -> ApiError.BOOK_NOT_FOUND.createException(bookId));
|
||||
Book book = bookMapper.toBook(bookEntity);
|
||||
if (request.getProvider() == MetadataProvider.AMAZON) {
|
||||
return amazonBookParser.fetchTopNMetadata(book, request, GET_METADATA_COUNT);
|
||||
@@ -90,7 +90,7 @@ public class BookMetadataService {
|
||||
|
||||
|
||||
public BookMetadata setBookMetadata(long bookId, FetchedBookMetadata newMetadata, MetadataProvider source, boolean setThumbnail) {
|
||||
BookEntity bookEntity = bookEntityRepository.findById(bookId).orElseThrow(() -> ApiError.BOOK_NOT_FOUND.createException(bookId));
|
||||
BookEntity bookEntity = bookRepository.findById(bookId).orElseThrow(() -> ApiError.BOOK_NOT_FOUND.createException(bookId));
|
||||
BookMetadataEntity metadata = bookEntity.getMetadata();
|
||||
metadata.setTitle(newMetadata.getTitle());
|
||||
metadata.setSubtitle(newMetadata.getSubtitle());
|
||||
|
||||
Reference in New Issue
Block a user