Update metadata
This commit is contained in:
+6
-4
@@ -2,15 +2,12 @@ package com.adityachandel.booklore.controller;
|
||||
|
||||
import com.adityachandel.booklore.mapper.BookMetadataMapper;
|
||||
import com.adityachandel.booklore.model.dto.BookMetadata;
|
||||
import com.adityachandel.booklore.model.dto.request.BooksMetadataRefreshRequest;
|
||||
import com.adityachandel.booklore.model.dto.request.LibraryMetadataRefreshRequest;
|
||||
import com.adityachandel.booklore.model.dto.request.MetadataRefreshRequest;
|
||||
import com.adityachandel.booklore.quartz.JobSchedulerService;
|
||||
import com.adityachandel.booklore.service.metadata.BookMetadataService;
|
||||
import com.adityachandel.booklore.service.metadata.BookMetadataUpdater;
|
||||
import com.adityachandel.booklore.service.metadata.model.FetchMetadataRequest;
|
||||
import com.adityachandel.booklore.service.metadata.model.FetchedBookMetadata;
|
||||
import com.adityachandel.booklore.service.metadata.model.MetadataProvider;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
@@ -34,11 +31,16 @@ public class MetadataController {
|
||||
}
|
||||
|
||||
@PutMapping("/{bookId}")
|
||||
public ResponseEntity<BookMetadata> updateMetadata(@RequestBody FetchedBookMetadata setMetadataRequest, @PathVariable long bookId) {
|
||||
public ResponseEntity<BookMetadata> updateMetadataFromFetch(@RequestBody FetchedBookMetadata setMetadataRequest, @PathVariable long bookId) {
|
||||
BookMetadata bookMetadata = bookMetadataMapper.toBookMetadata(bookMetadataUpdater.setBookMetadata(bookId, setMetadataRequest, true), true);
|
||||
return ResponseEntity.ok(bookMetadata);
|
||||
}
|
||||
|
||||
@PutMapping("/update/{bookId}")
|
||||
public ResponseEntity<BookMetadata> updateMetadata(@PathVariable long bookId, @RequestBody BookMetadata bookMetadata) {
|
||||
return ResponseEntity.ok(bookMetadataUpdater.updateMetadata(bookId, bookMetadata));
|
||||
}
|
||||
|
||||
@PutMapping(path = "/refreshV2")
|
||||
public ResponseEntity<String> scheduleRefreshV2(@Validated @RequestBody MetadataRefreshRequest request) {
|
||||
jobSchedulerService.scheduleMetadataRefreshV2(request);
|
||||
|
||||
@@ -10,4 +10,7 @@ import java.util.List;
|
||||
public interface AuthorMapper {
|
||||
Author toAuthor(AuthorEntity authorEntity);
|
||||
List<Author> toAuthorList(List<AuthorEntity> authorEntities);
|
||||
|
||||
AuthorEntity toAuthorEntity(Author author);
|
||||
List<AuthorEntity> toAuthorEntityList(List<Author> authors);
|
||||
}
|
||||
|
||||
@@ -13,4 +13,7 @@ public interface CategoryMapper {
|
||||
|
||||
List<Category> toCategoryList(List<CategoryEntity> entities);
|
||||
|
||||
CategoryEntity toCategoryEntity(Category category);
|
||||
|
||||
List<CategoryEntity> toCategoryEntities(List<Category> categories);
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ public class BookMetadata {
|
||||
private String isbn10;
|
||||
private Integer pageCount;
|
||||
private String language;
|
||||
private Float rating;
|
||||
private Double rating;
|
||||
private Integer reviewCount;
|
||||
private Instant coverUpdatedOn;
|
||||
private List<Author> authors;
|
||||
|
||||
+56
@@ -1,7 +1,10 @@
|
||||
package com.adityachandel.booklore.service.metadata;
|
||||
|
||||
import com.adityachandel.booklore.exception.ApiError;
|
||||
import com.adityachandel.booklore.mapper.AuthorMapper;
|
||||
import com.adityachandel.booklore.mapper.BookMetadataMapper;
|
||||
import com.adityachandel.booklore.mapper.CategoryMapper;
|
||||
import com.adityachandel.booklore.model.dto.BookMetadata;
|
||||
import com.adityachandel.booklore.model.entity.AuthorEntity;
|
||||
import com.adityachandel.booklore.model.entity.BookEntity;
|
||||
import com.adityachandel.booklore.model.entity.BookMetadataEntity;
|
||||
@@ -32,6 +35,9 @@ public class BookMetadataUpdater {
|
||||
private BookMetadataRepository bookMetadataRepository;
|
||||
private CategoryRepository categoryRepository;
|
||||
private FileService fileService;
|
||||
private BookMetadataMapper bookMetadataMapper;
|
||||
private AuthorMapper authorMapper;
|
||||
private CategoryMapper categoryMapper;
|
||||
|
||||
|
||||
@Transactional(propagation = Propagation.REQUIRES_NEW)
|
||||
@@ -87,4 +93,54 @@ public class BookMetadataUpdater {
|
||||
return metadata;
|
||||
}
|
||||
|
||||
public BookMetadata updateMetadata(long bookId, BookMetadata updatedMetadata) {
|
||||
BookEntity bookEntity = bookRepository.findById(bookId).orElseThrow(() -> ApiError.BOOK_NOT_FOUND.createException(bookId));
|
||||
BookMetadataEntity metadata = bookEntity.getMetadata();
|
||||
|
||||
if (updatedMetadata.getTitle() != null) {
|
||||
metadata.setTitle(updatedMetadata.getTitle());
|
||||
}
|
||||
if (updatedMetadata.getSubtitle() != null) {
|
||||
metadata.setSubtitle(updatedMetadata.getSubtitle());
|
||||
}
|
||||
if (updatedMetadata.getPublisher() != null) {
|
||||
metadata.setPublisher(updatedMetadata.getPublisher());
|
||||
}
|
||||
if (updatedMetadata.getPublishedDate() != null) {
|
||||
metadata.setPublishedDate(updatedMetadata.getPublishedDate());
|
||||
}
|
||||
if (updatedMetadata.getDescription() != null) {
|
||||
metadata.setDescription(updatedMetadata.getDescription());
|
||||
}
|
||||
if (updatedMetadata.getIsbn13() != null) {
|
||||
metadata.setIsbn13(updatedMetadata.getIsbn13());
|
||||
}
|
||||
if (updatedMetadata.getIsbn10() != null) {
|
||||
metadata.setIsbn10(updatedMetadata.getIsbn10());
|
||||
}
|
||||
if (updatedMetadata.getPageCount() != null) {
|
||||
metadata.setPageCount(updatedMetadata.getPageCount());
|
||||
}
|
||||
if (updatedMetadata.getLanguage() != null) {
|
||||
metadata.setLanguage(updatedMetadata.getLanguage());
|
||||
}
|
||||
if (updatedMetadata.getRating() != null) {
|
||||
metadata.setRating(updatedMetadata.getRating());
|
||||
}
|
||||
if (updatedMetadata.getReviewCount() != null) {
|
||||
metadata.setReviewCount(updatedMetadata.getReviewCount());
|
||||
}
|
||||
if (updatedMetadata.getCoverUpdatedOn() != null) {
|
||||
metadata.setCoverUpdatedOn(updatedMetadata.getCoverUpdatedOn());
|
||||
}
|
||||
if (updatedMetadata.getAuthors() != null) {
|
||||
metadata.setAuthors(authorMapper.toAuthorEntityList(updatedMetadata.getAuthors()));
|
||||
}
|
||||
if (updatedMetadata.getCategories() != null) {
|
||||
metadata.setCategories(categoryMapper.toCategoryEntities(updatedMetadata.getCategories()));
|
||||
}
|
||||
bookRepository.save(bookEntity);
|
||||
return bookMetadataMapper.toBookMetadata(metadata, false);
|
||||
}
|
||||
|
||||
}
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
package com.adityachandel.booklore.service.metadata;
|
||||
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
public class SimpleMetadataUpdaterService {
|
||||
}
|
||||
@@ -5,7 +5,7 @@ VALUES
|
||||
INSERT INTO app_settings (category, name, val)
|
||||
VALUES
|
||||
('epub', 'theme', 'white'),
|
||||
('epub', 'fontSize', '120'),
|
||||
('epub', 'fontSize', '150'),
|
||||
('epub', 'font', 'serif');
|
||||
|
||||
INSERT INTO app_settings (category, name, val)
|
||||
|
||||
Reference in New Issue
Block a user