WIP: Add filter sidebar
This commit is contained in:
+21
-1
@@ -7,9 +7,9 @@ import com.adityachandel.booklore.repository.*;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.io.File;
|
||||
import java.time.Instant;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
|
||||
@@ -18,6 +18,7 @@ import java.util.Set;
|
||||
public class BookCreatorService {
|
||||
|
||||
private AuthorRepository authorRepository;
|
||||
private CategoryRepository categoryRepository;
|
||||
private BookRepository bookRepository;
|
||||
private BookMetadataRepository bookMetadataRepository;
|
||||
private PdfViewerPreferencesRepository pdfViewerPreferencesRepository;
|
||||
@@ -52,6 +53,25 @@ public class BookCreatorService {
|
||||
return bookEntity;
|
||||
}
|
||||
|
||||
public void addCategoriesToBook(List<String> categories, BookEntity bookEntity) {
|
||||
for (String category : categories) {
|
||||
Optional<CategoryEntity> catOpt = categoryRepository.findByName(category);
|
||||
CategoryEntity categoryEntity;
|
||||
if (catOpt.isPresent()) {
|
||||
categoryEntity = catOpt.get();
|
||||
} else {
|
||||
categoryEntity = CategoryEntity.builder()
|
||||
.name(category)
|
||||
.build();
|
||||
categoryEntity = categoryRepository.save(categoryEntity);
|
||||
}
|
||||
if (bookEntity.getMetadata().getCategories() == null) {
|
||||
bookEntity.getMetadata().setCategories(new ArrayList<>());
|
||||
}
|
||||
bookEntity.getMetadata().getCategories().add(categoryEntity);
|
||||
}
|
||||
}
|
||||
|
||||
public void addAuthorsToBook(Set<String> authors, BookEntity bookEntity) {
|
||||
for (String authorStr : authors) {
|
||||
Optional<AuthorEntity> authorOptional = authorRepository.findByName(authorStr);
|
||||
|
||||
+1
@@ -138,6 +138,7 @@ public class EpubProcessor implements FileProcessor {
|
||||
}
|
||||
|
||||
bookCreatorService.addAuthorsToBook(getAuthors(book), bookEntity);
|
||||
bookCreatorService.addCategoriesToBook(epubMetadata.getSubjects(), bookEntity);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user