WIP: Locking
This commit is contained in:
+11
-2
@@ -2,6 +2,7 @@ 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.FieldLockRequest;
|
||||
import com.adityachandel.booklore.model.dto.request.MetadataRefreshRequest;
|
||||
import com.adityachandel.booklore.quartz.JobSchedulerService;
|
||||
import com.adityachandel.booklore.service.metadata.BookMetadataService;
|
||||
@@ -36,14 +37,22 @@ public class MetadataController {
|
||||
return ResponseEntity.ok(bookMetadata);
|
||||
}
|
||||
|
||||
@PutMapping("/update/{bookId}")
|
||||
/*@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);
|
||||
return ResponseEntity.noContent().build();
|
||||
}
|
||||
|
||||
@PutMapping("/lock")
|
||||
public ResponseEntity<BookMetadata> updateFieldLockState(@RequestBody FieldLockRequest request) {
|
||||
long bookId = request.getBookId();
|
||||
String field = request.getField();
|
||||
boolean isLocked = request.getIsLocked();
|
||||
return ResponseEntity.ok(bookMetadataService.updateFieldLockState(bookId, field, isLocked));
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.adityachandel.booklore.model.dto;
|
||||
|
||||
import jakarta.persistence.Column;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
|
||||
@@ -32,6 +33,8 @@ public class BookMetadata {
|
||||
|
||||
private Boolean allFieldsLocked;
|
||||
private Boolean titleLocked;
|
||||
private Boolean authorsLocked;
|
||||
private Boolean categoriesLocked;
|
||||
private Boolean subtitleLocked;
|
||||
private Boolean publisherLocked;
|
||||
private Boolean publishedDateLocked;
|
||||
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
package com.adityachandel.booklore.model.dto.request;
|
||||
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class FieldLockRequest {
|
||||
|
||||
@NotNull(message = "Book ID must not be null")
|
||||
private Long bookId;
|
||||
|
||||
@NotNull(message = "Field must not be null")
|
||||
private String field;
|
||||
|
||||
private Boolean isLocked;
|
||||
}
|
||||
+54
-1
@@ -2,8 +2,10 @@ package com.adityachandel.booklore.service.metadata;
|
||||
|
||||
import com.adityachandel.booklore.exception.ApiError;
|
||||
import com.adityachandel.booklore.mapper.BookMapper;
|
||||
import com.adityachandel.booklore.mapper.BookMetadataMapper;
|
||||
import com.adityachandel.booklore.model.dto.Author;
|
||||
import com.adityachandel.booklore.model.dto.Book;
|
||||
import com.adityachandel.booklore.model.dto.BookMetadata;
|
||||
import com.adityachandel.booklore.model.dto.request.MetadataRefreshOptions;
|
||||
import com.adityachandel.booklore.model.dto.request.MetadataRefreshRequest;
|
||||
import com.adityachandel.booklore.model.dto.settings.AppSettings;
|
||||
@@ -11,6 +13,7 @@ import com.adityachandel.booklore.model.entity.BookEntity;
|
||||
import com.adityachandel.booklore.model.entity.BookMetadataEntity;
|
||||
import com.adityachandel.booklore.model.entity.LibraryEntity;
|
||||
import com.adityachandel.booklore.model.websocket.Topic;
|
||||
import com.adityachandel.booklore.repository.BookMetadataRepository;
|
||||
import com.adityachandel.booklore.repository.BookRepository;
|
||||
import com.adityachandel.booklore.repository.LibraryRepository;
|
||||
import com.adityachandel.booklore.service.AppSettingService;
|
||||
@@ -40,9 +43,11 @@ public class BookMetadataService {
|
||||
private final BookRepository bookRepository;
|
||||
private final LibraryRepository libraryRepository;
|
||||
private final BookMapper bookMapper;
|
||||
private final BookMetadataMapper bookMetadataMapper;
|
||||
private final BookMetadataUpdater bookMetadataUpdater;
|
||||
private final NotificationService notificationService;
|
||||
private final AppSettingService appSettingService;
|
||||
private final BookMetadataRepository bookMetadataRepository;
|
||||
private final Map<MetadataProvider, BookParser> parserMap;
|
||||
|
||||
|
||||
@@ -97,7 +102,7 @@ public class BookMetadataService {
|
||||
for (BookEntity bookEntity : books) {
|
||||
try {
|
||||
Boolean allFieldsLocked = bookEntity.getMetadata().getAllFieldsLocked();
|
||||
if (allFieldsLocked) {
|
||||
if (Boolean.TRUE.equals(allFieldsLocked)) {
|
||||
log.info("Skipping metadata refresh for locked book: {}", bookEntity.getFileName());
|
||||
continue;
|
||||
}
|
||||
@@ -335,4 +340,52 @@ public class BookMetadataService {
|
||||
}
|
||||
return parser;
|
||||
}
|
||||
|
||||
public BookMetadata updateFieldLockState(long bookId, String field, boolean isLocked) {
|
||||
BookMetadataEntity existingMetadata = bookMetadataRepository.findById(bookId).orElseThrow(() -> new RuntimeException("Book metadata not found"));
|
||||
switch (field) {
|
||||
case "title":
|
||||
existingMetadata.setTitleLocked(isLocked);
|
||||
break;
|
||||
case "subtitle":
|
||||
existingMetadata.setSubtitleLocked(isLocked);
|
||||
break;
|
||||
case "authors":
|
||||
existingMetadata.setAuthorsLocked(isLocked);
|
||||
break;
|
||||
case "categories":
|
||||
existingMetadata.setCategoriesLocked(isLocked);
|
||||
break;
|
||||
case "publisher":
|
||||
existingMetadata.setPublisherLocked(isLocked);
|
||||
break;
|
||||
case "publishedDate":
|
||||
existingMetadata.setPublishedDateLocked(isLocked);
|
||||
break;
|
||||
case "isbn10":
|
||||
existingMetadata.setIsbn10Locked(isLocked);
|
||||
break;
|
||||
case "isbn13":
|
||||
existingMetadata.setIsbn13Locked(isLocked);
|
||||
break;
|
||||
case "description":
|
||||
existingMetadata.setDescriptionLocked(isLocked);
|
||||
break;
|
||||
case "pageCount":
|
||||
existingMetadata.setPageCountLocked(isLocked);
|
||||
break;
|
||||
case "language":
|
||||
existingMetadata.setLanguageLocked(isLocked);
|
||||
break;
|
||||
case "rating":
|
||||
existingMetadata.setRatingLocked(isLocked);
|
||||
break;
|
||||
case "reviewCount":
|
||||
existingMetadata.setReviewCountLocked(isLocked);
|
||||
break;
|
||||
default:
|
||||
throw new IllegalArgumentException("Invalid field name: " + field);
|
||||
}
|
||||
return bookMetadataMapper.toBookMetadata(bookMetadataRepository.save(existingMetadata), true);
|
||||
}
|
||||
}
|
||||
+134
-51
@@ -21,6 +21,7 @@ import java.time.ZoneId;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Slf4j
|
||||
@@ -44,108 +45,132 @@ public class BookMetadataUpdater {
|
||||
BookEntity bookEntity = bookRepository.findById(bookId).orElseThrow(() -> ApiError.BOOK_NOT_FOUND.createException(bookId));
|
||||
BookMetadataEntity metadata = bookEntity.getMetadata();
|
||||
|
||||
if (metadata.getAllFieldsLocked()) {
|
||||
updateLocks(newMetadata, metadata);
|
||||
|
||||
if (Boolean.TRUE.equals(metadata.getAllFieldsLocked())) {
|
||||
log.warn("Attempted to update metadata for book with ID {}, but all fields are locked. No update performed.", bookId);
|
||||
return metadata;
|
||||
}
|
||||
|
||||
if (!metadata.getTitleLocked() && newMetadata.getTitle() != null && !newMetadata.getTitle().isBlank()) {
|
||||
metadata.setTitle(newMetadata.getTitle());
|
||||
if ((metadata.getTitleLocked() == null || !metadata.getTitleLocked()) && newMetadata.getTitle() != null) {
|
||||
metadata.setTitle(newMetadata.getTitle().isEmpty() ? null : newMetadata.getTitle());
|
||||
}
|
||||
if (!metadata.getSubtitleLocked() && newMetadata.getSubtitle() != null && !newMetadata.getSubtitle().isBlank()) {
|
||||
metadata.setSubtitle(newMetadata.getSubtitle());
|
||||
|
||||
if ((metadata.getSubtitleLocked() == null || !metadata.getSubtitleLocked()) && newMetadata.getSubtitle() != null) {
|
||||
metadata.setSubtitle(newMetadata.getSubtitle().isBlank() ? null : newMetadata.getSubtitle());
|
||||
}
|
||||
if (!metadata.getPublisherLocked() && newMetadata.getPublisher() != null && !newMetadata.getPublisher().isBlank()) {
|
||||
metadata.setPublisher(newMetadata.getPublisher());
|
||||
|
||||
if ((metadata.getPublisherLocked() == null || !metadata.getPublisherLocked()) && newMetadata.getPublisher() != null) {
|
||||
metadata.setPublisher(newMetadata.getPublisher().isBlank() ? null : newMetadata.getPublisher());
|
||||
}
|
||||
if (!metadata.getPublishedDateLocked() && newMetadata.getPublishedDate() != null) {
|
||||
|
||||
if ((metadata.getPublishedDateLocked() == null || !metadata.getPublishedDateLocked()) && newMetadata.getPublishedDate() != null) {
|
||||
metadata.setPublishedDate(newMetadata.getPublishedDate());
|
||||
}
|
||||
if (!metadata.getLanguageLocked() && newMetadata.getLanguage() != null && !newMetadata.getLanguage().isBlank()) {
|
||||
metadata.setLanguage(newMetadata.getLanguage());
|
||||
|
||||
if ((metadata.getLanguageLocked() == null || !metadata.getLanguageLocked()) && newMetadata.getLanguage() != null) {
|
||||
metadata.setLanguage(newMetadata.getLanguage().isBlank() ? null : newMetadata.getLanguage());
|
||||
}
|
||||
if (!metadata.getIsbn10Locked() && newMetadata.getIsbn10() != null && !newMetadata.getIsbn10().isBlank()) {
|
||||
metadata.setIsbn10(newMetadata.getIsbn10());
|
||||
|
||||
if ((metadata.getIsbn10Locked() == null || !metadata.getIsbn10Locked()) && newMetadata.getIsbn10() != null) {
|
||||
metadata.setIsbn10(newMetadata.getIsbn10().isBlank() ? null : newMetadata.getIsbn10());
|
||||
}
|
||||
if (!metadata.getIsbn13Locked() && newMetadata.getIsbn13() != null && !newMetadata.getIsbn13().isBlank()) {
|
||||
metadata.setIsbn13(newMetadata.getIsbn13());
|
||||
|
||||
if ((metadata.getIsbn13Locked() == null || !metadata.getIsbn13Locked()) && newMetadata.getIsbn13() != null) {
|
||||
metadata.setIsbn13(newMetadata.getIsbn13().isBlank() ? null : newMetadata.getIsbn13());
|
||||
}
|
||||
if (!metadata.getDescriptionLocked() && newMetadata.getDescription() != null && !newMetadata.getDescription().isBlank()) {
|
||||
metadata.setDescription(newMetadata.getDescription());
|
||||
|
||||
if ((metadata.getDescriptionLocked() == null || !metadata.getDescriptionLocked()) && newMetadata.getDescription() != null) {
|
||||
metadata.setDescription(newMetadata.getDescription().isBlank() ? null : newMetadata.getDescription());
|
||||
}
|
||||
if (!metadata.getPageCountLocked() && newMetadata.getPageCount() != null) {
|
||||
|
||||
if ((metadata.getPageCountLocked() == null || !metadata.getPageCountLocked()) && newMetadata.getPageCount() != null) {
|
||||
metadata.setPageCount(newMetadata.getPageCount());
|
||||
}
|
||||
if (!metadata.getRatingLocked() && newMetadata.getRating() != null) {
|
||||
|
||||
if ((metadata.getRatingLocked() == null || !metadata.getRatingLocked()) && newMetadata.getRating() != null) {
|
||||
metadata.setRating(newMetadata.getRating());
|
||||
}
|
||||
if (!metadata.getReviewCountLocked() && newMetadata.getReviewCount() != null) {
|
||||
|
||||
if ((metadata.getReviewCountLocked() == null || !metadata.getReviewCountLocked()) && newMetadata.getReviewCount() != null) {
|
||||
metadata.setReviewCount(newMetadata.getReviewCount());
|
||||
}
|
||||
if (!metadata.getSeriesNameLocked() && newMetadata.getSeriesName() != null) {
|
||||
|
||||
if ((metadata.getSeriesNameLocked() == null || !metadata.getSeriesNameLocked()) && newMetadata.getSeriesName() != null) {
|
||||
metadata.setSeriesName(newMetadata.getSeriesName());
|
||||
}
|
||||
if (!metadata.getSeriesNumberLocked() && newMetadata.getSeriesNumber() != null) {
|
||||
|
||||
if ((metadata.getSeriesNumberLocked() == null || !metadata.getSeriesNumberLocked()) && newMetadata.getSeriesNumber() != null) {
|
||||
metadata.setSeriesNumber(newMetadata.getSeriesNumber());
|
||||
}
|
||||
if (!metadata.getSeriesTotalLocked() && newMetadata.getSeriesTotal() != null) {
|
||||
|
||||
if ((metadata.getSeriesTotalLocked() == null || !metadata.getSeriesTotalLocked()) && newMetadata.getSeriesTotal() != null) {
|
||||
metadata.setSeriesTotal(newMetadata.getSeriesTotal());
|
||||
}
|
||||
|
||||
if (newMetadata.getAwards() != null && !newMetadata.getAwards().isEmpty()) {
|
||||
HashSet<BookAwardEntity> newAwards = new HashSet<>();
|
||||
newMetadata.getAwards()
|
||||
.stream()
|
||||
.filter(Objects::nonNull)
|
||||
.forEach(award -> {
|
||||
boolean awardExists = bookMetadataRepository.findAwardByBookIdAndNameAndCategoryAndAwardedAt(
|
||||
metadata.getBookId(),
|
||||
award.getName(),
|
||||
award.getCategory(),
|
||||
award.getAwardedAt()) != null;
|
||||
|
||||
newMetadata.getAwards().forEach(award -> {
|
||||
boolean awardExists = bookMetadataRepository.findAwardByBookIdAndNameAndCategoryAndAwardedAt(
|
||||
metadata.getBookId(),
|
||||
award.getName(),
|
||||
award.getCategory(),
|
||||
award.getAwardedAt()) != null;
|
||||
if (!awardExists) {
|
||||
BookAwardEntity awardEntity = new BookAwardEntity();
|
||||
awardEntity.setBook(metadata);
|
||||
awardEntity.setName(award.getName());
|
||||
awardEntity.setCategory(award.getCategory());
|
||||
awardEntity.setDesignation(award.getDesignation());
|
||||
awardEntity.setAwardedAt(award.getAwardedAt() != null ? award.getAwardedAt() : Instant.now().atZone(ZoneId.systemDefault()).toLocalDate());
|
||||
|
||||
if (!awardExists) {
|
||||
BookAwardEntity awardEntity = new BookAwardEntity();
|
||||
awardEntity.setBook(metadata);
|
||||
awardEntity.setName(award.getName());
|
||||
awardEntity.setCategory(award.getCategory());
|
||||
awardEntity.setDesignation(award.getDesignation());
|
||||
awardEntity.setAwardedAt(award.getAwardedAt() != null ? award.getAwardedAt() : Instant.now().atZone(ZoneId.systemDefault()).toLocalDate());
|
||||
|
||||
newAwards.add(awardEntity);
|
||||
}
|
||||
});
|
||||
newAwards.add(awardEntity);
|
||||
}
|
||||
});
|
||||
if (!newAwards.isEmpty()) {
|
||||
metadata.setAwards(new ArrayList<>(newAwards));
|
||||
bookAwardRepository.saveAll(newAwards);
|
||||
}
|
||||
}
|
||||
|
||||
if (!metadata.getAuthorsLocked() && newMetadata.getAuthors() != null && !newMetadata.getAuthors().isEmpty()) {
|
||||
metadata.setAuthors(newMetadata.getAuthors().stream()
|
||||
if ((metadata.getAuthorsLocked() == null || !metadata.getAuthorsLocked()) && newMetadata.getAuthors() != null && !newMetadata.getAuthors().isEmpty()) {
|
||||
metadata.setAuthors(newMetadata.getAuthors()
|
||||
.stream()
|
||||
.filter(a -> a != null && !a.isBlank())
|
||||
.map(authorName -> authorRepository.findByName(authorName)
|
||||
.orElseGet(() -> authorRepository.save(AuthorEntity.builder().name(authorName).build())))
|
||||
.collect(Collectors.toList()));
|
||||
}
|
||||
|
||||
if (mergeCategories) {
|
||||
if (!metadata.getCategoriesLocked() && newMetadata.getCategories() != null) {
|
||||
if ((metadata.getCategoriesLocked() == null || !metadata.getCategoriesLocked()) && newMetadata.getCategories() != null) {
|
||||
HashSet<CategoryEntity> existingCategories = new HashSet<>(metadata.getCategories());
|
||||
newMetadata.getCategories().forEach(categoryName -> {
|
||||
CategoryEntity categoryEntity = categoryRepository.findByName(categoryName)
|
||||
.orElseGet(() -> categoryRepository.save(CategoryEntity.builder().name(categoryName).build()));
|
||||
existingCategories.add(categoryEntity);
|
||||
});
|
||||
newMetadata.getCategories()
|
||||
.stream()
|
||||
.filter(c -> c != null && !c.isBlank())
|
||||
.forEach(categoryName -> {
|
||||
CategoryEntity categoryEntity = categoryRepository.findByName(categoryName)
|
||||
.orElseGet(() -> categoryRepository.save(CategoryEntity.builder().name(categoryName).build()));
|
||||
existingCategories.add(categoryEntity);
|
||||
});
|
||||
metadata.setCategories(new ArrayList<>(existingCategories));
|
||||
}
|
||||
} else {
|
||||
if (!metadata.getCategoriesLocked() && newMetadata.getCategories() != null && !newMetadata.getCategories().isEmpty()) {
|
||||
metadata.setCategories(newMetadata.getCategories().stream()
|
||||
if ((metadata.getCategoriesLocked() == null || !metadata.getCategoriesLocked()) && newMetadata.getCategories() != null && !newMetadata.getCategories().isEmpty()) {
|
||||
metadata.setCategories(newMetadata.getCategories()
|
||||
.stream()
|
||||
.filter(c -> c != null && !c.isBlank())
|
||||
.map(categoryName -> categoryRepository.findByName(categoryName)
|
||||
.orElseGet(() -> categoryRepository.save(CategoryEntity.builder().name(categoryName).build())))
|
||||
.collect(Collectors.toList()));
|
||||
}
|
||||
}
|
||||
|
||||
if (setThumbnail && !metadata.getCoverLocked() && newMetadata.getThumbnailUrl() != null && !newMetadata.getThumbnailUrl().isEmpty()) {
|
||||
if (setThumbnail && (metadata.getThumbnailLocked() == null || !metadata.getThumbnailLocked()) && newMetadata.getThumbnailUrl() != null && !newMetadata.getThumbnailUrl().isEmpty()) {
|
||||
String thumbnailPath = null;
|
||||
try {
|
||||
thumbnailPath = fileService.createThumbnail(bookId, newMetadata.getThumbnailUrl());
|
||||
@@ -167,13 +192,71 @@ public class BookMetadataUpdater {
|
||||
return metadata;
|
||||
}
|
||||
|
||||
private void updateLocks(FetchedBookMetadata newMetadata, BookMetadataEntity metadata) {
|
||||
if (newMetadata.getTitleLocked() != null) {
|
||||
metadata.setTitleLocked(newMetadata.getTitleLocked());
|
||||
}
|
||||
if (newMetadata.getSubtitleLocked() != null) {
|
||||
metadata.setSubtitleLocked(newMetadata.getSubtitleLocked());
|
||||
}
|
||||
if (newMetadata.getPublisherLocked() != null) {
|
||||
metadata.setPublisherLocked(newMetadata.getPublisherLocked());
|
||||
}
|
||||
if (newMetadata.getPublishedDateLocked() != null) {
|
||||
metadata.setPublishedDateLocked(newMetadata.getPublishedDateLocked());
|
||||
}
|
||||
if (newMetadata.getDescriptionLocked() != null) {
|
||||
metadata.setDescriptionLocked(newMetadata.getDescriptionLocked());
|
||||
}
|
||||
if (newMetadata.getIsbn13Locked() != null) {
|
||||
metadata.setIsbn13Locked(newMetadata.getIsbn13Locked());
|
||||
}
|
||||
if (newMetadata.getIsbn10Locked() != null) {
|
||||
metadata.setIsbn10Locked(newMetadata.getIsbn10Locked());
|
||||
}
|
||||
if (newMetadata.getPageCountLocked() != null) {
|
||||
metadata.setPageCountLocked(newMetadata.getPageCountLocked());
|
||||
}
|
||||
if (newMetadata.getLanguageLocked() != null) {
|
||||
metadata.setLanguageLocked(newMetadata.getLanguageLocked());
|
||||
}
|
||||
if (newMetadata.getRatingLocked() != null) {
|
||||
metadata.setRatingLocked(newMetadata.getRatingLocked());
|
||||
}
|
||||
if (newMetadata.getReviewCountLocked() != null) {
|
||||
metadata.setReviewCountLocked(newMetadata.getReviewCountLocked());
|
||||
}
|
||||
if (newMetadata.getSeriesNameLocked() != null) {
|
||||
metadata.setSeriesNameLocked(newMetadata.getSeriesNameLocked());
|
||||
}
|
||||
if (newMetadata.getSeriesNumberLocked() != null) {
|
||||
metadata.setSeriesNumberLocked(newMetadata.getSeriesNumberLocked());
|
||||
}
|
||||
if (newMetadata.getSeriesTotalLocked() != null) {
|
||||
metadata.setSeriesTotalLocked(newMetadata.getSeriesTotalLocked());
|
||||
}
|
||||
if (newMetadata.getAuthorsLocked() != null) {
|
||||
metadata.setAuthorsLocked(newMetadata.getAuthorsLocked());
|
||||
}
|
||||
if (newMetadata.getCategoriesLocked() != null) {
|
||||
metadata.setCategoriesLocked(newMetadata.getCategoriesLocked());
|
||||
}
|
||||
if (newMetadata.getCoverLocked() != null) {
|
||||
metadata.setCoverLocked(newMetadata.getCoverLocked());
|
||||
}
|
||||
if (newMetadata.getAllFieldsLocked() != null) {
|
||||
metadata.setAllFieldsLocked(newMetadata.getAllFieldsLocked());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public BookMetadata updateMetadata(long bookId, BookMetadata updatedMetadata) {
|
||||
BookEntity bookEntity = bookRepository.findById(bookId).orElseThrow(() -> ApiError.BOOK_NOT_FOUND.createException(bookId));
|
||||
BookMetadataEntity metadata = bookEntity.getMetadata();
|
||||
|
||||
List<String> lockedFields = new ArrayList<>();
|
||||
|
||||
if (metadata.getAllFieldsLocked()) {
|
||||
if (metadata.getAllFieldsLocked() != null && metadata.getAllFieldsLocked()) {
|
||||
log.warn("Attempted to update metadata for book with ID {}, but all fields are locked. No update performed.", bookId);
|
||||
throw ApiError.METADATA_LOCKED.createException(bookId);
|
||||
}
|
||||
|
||||
+19
@@ -33,4 +33,23 @@ public class FetchedBookMetadata {
|
||||
private List<String> authors;
|
||||
private List<String> categories;
|
||||
private List<Award> awards;
|
||||
|
||||
private Boolean allFieldsLocked;
|
||||
private Boolean titleLocked;
|
||||
private Boolean authorsLocked;
|
||||
private Boolean categoriesLocked;
|
||||
private Boolean subtitleLocked;
|
||||
private Boolean publisherLocked;
|
||||
private Boolean publishedDateLocked;
|
||||
private Boolean descriptionLocked;
|
||||
private Boolean isbn13Locked;
|
||||
private Boolean isbn10Locked;
|
||||
private Boolean pageCountLocked;
|
||||
private Boolean languageLocked;
|
||||
private Boolean ratingLocked;
|
||||
private Boolean reviewCountLocked;
|
||||
private Boolean coverLocked;
|
||||
private Boolean seriesNameLocked;
|
||||
private Boolean seriesNumberLocked;
|
||||
private Boolean seriesTotalLocked;
|
||||
}
|
||||
@@ -69,6 +69,8 @@ CREATE TABLE IF NOT EXISTS book_metadata
|
||||
thumbnail_locked BOOLEAN DEFAULT FALSE,
|
||||
language_locked BOOLEAN DEFAULT FALSE,
|
||||
cover_locked BOOLEAN DEFAULT FALSE,
|
||||
rating_locked BOOLEAN DEFAULT FALSE,
|
||||
review_count_locked BOOLEAN DEFAULT FALSE,
|
||||
series_name_locked BOOLEAN DEFAULT FALSE,
|
||||
series_number_locked BOOLEAN DEFAULT FALSE,
|
||||
series_total_locked BOOLEAN DEFAULT FALSE,
|
||||
|
||||
@@ -36,6 +36,26 @@ export interface BookMetadata {
|
||||
categories: Category[];
|
||||
awards?: Award[];
|
||||
|
||||
titleLocked?: boolean;
|
||||
subtitleLocked?: boolean;
|
||||
publisherLocked?: boolean;
|
||||
publishedDateLocked?: boolean;
|
||||
descriptionLocked?: boolean;
|
||||
seriesNameLocked?: boolean;
|
||||
seriesNumberLocked?: boolean;
|
||||
seriesTotalLocked?: boolean;
|
||||
isbn13Locked?: boolean;
|
||||
isbn10Locked?: boolean;
|
||||
asinLocked?: boolean;
|
||||
pageCountLocked?: boolean;
|
||||
languageLocked?: boolean;
|
||||
ratingLocked?: boolean;
|
||||
reviewCountLocked?: boolean;
|
||||
coverUpdatedOnLocked?: boolean;
|
||||
authorsLocked?: boolean;
|
||||
categoriesLocked?: boolean;
|
||||
awardsLocked?: boolean;
|
||||
|
||||
[key: string]: any;
|
||||
}
|
||||
|
||||
|
||||
@@ -203,4 +203,21 @@ export class BookService {
|
||||
const book = this.bookStateSubject.value.books?.find(book => book.id === bookId);
|
||||
return book?.metadata ?? null;
|
||||
}
|
||||
|
||||
updateLock(bookId: number, field: string, isLocked: boolean): void {
|
||||
const currentState = this.bookStateSubject.value;
|
||||
const updatedBooks = (currentState.books || []).map(book => {
|
||||
if (book.id === bookId && book.metadata) {
|
||||
return {
|
||||
...book,
|
||||
metadata: {
|
||||
...book.metadata,
|
||||
[`${field}Locked`]: isLocked
|
||||
}
|
||||
};
|
||||
}
|
||||
return book;
|
||||
});
|
||||
this.bookStateSubject.next({...currentState, books: updatedBooks});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,7 +14,6 @@ export class BookMetadataCenterService {
|
||||
dialogClose$ = this.dialogCloseSubject.asObservable();
|
||||
|
||||
emit(bookMetadata: BookMetadata) {
|
||||
console.log(bookMetadata)
|
||||
this.bookMetadataSubject.next(bookMetadata);
|
||||
}
|
||||
|
||||
|
||||
+85
-38
@@ -1,4 +1,4 @@
|
||||
<form [formGroup]="bookMetadataForm" (ngSubmit)="onSave()" *ngIf="bookMetadata$ | async as metadata" class="pt-2 flex flex-col h-full">
|
||||
<form [formGroup]="bookMetadataForm" (ngSubmit)="onSave('saveButton')" *ngIf="bookMetadata$ | async as metadata" class="pt-2 flex flex-col h-full">
|
||||
|
||||
<div class="overflow-y-scroll flex-1">
|
||||
|
||||
@@ -8,89 +8,136 @@
|
||||
|
||||
<div class="flex flex-col flex-grow pl-2">
|
||||
|
||||
<!-- Title and Subtitle -->
|
||||
<div class="flex flex-row w-full gap-4 pb-1">
|
||||
<div class="flex flex-col gap-1 w-2/3">
|
||||
<label for="title">Title</label>
|
||||
<input pInputText id="title" formControlName="title" class="w-full"/>
|
||||
<div class="flex justify-between items-center gap-2">
|
||||
<input pInputText id="title" formControlName="title" class="w-full"/>
|
||||
<p-button *ngIf="!metadata['titleLocked']" icon="pi pi-lock-open" [outlined]="true" (onClick)="toggleLock('title')" severity="success"></p-button>
|
||||
<p-button *ngIf="metadata['titleLocked']" icon="pi pi-lock" [outlined]="true" (onClick)="toggleLock('title')" severity="warn"></p-button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="flex flex-col gap-1 w-1/3">
|
||||
<label for="subtitle">Subtitle</label>
|
||||
<input pInputText id="subtitle" formControlName="subtitle" class="w-full"/>
|
||||
<div class="flex justify-between items-center gap-2">
|
||||
<input pInputText id="subtitle" formControlName="subtitle" class="w-full"/>
|
||||
<p-button *ngIf="!metadata['subtitleLocked']" icon="pi pi-lock-open" [outlined]="true" (onClick)="toggleLock('subtitle')" severity="success"></p-button>
|
||||
<p-button *ngIf="metadata['subtitleLocked']" icon="pi pi-lock" [outlined]="true" (onClick)="toggleLock('subtitle')" severity="warn"></p-button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Authors and Publisher -->
|
||||
<div class="flex flex-row w-full gap-4 mt-2 pb-1">
|
||||
<div class="flex flex-col gap-1 w-2/3">
|
||||
<label for="authors">Authors</label>
|
||||
<input pInputText id="authors" formControlName="authors" class="w-full"/>
|
||||
<div class="flex justify-between items-center gap-2">
|
||||
<input pInputText id="authors" formControlName="authors" class="w-full"/>
|
||||
<p-button *ngIf="!metadata['authorsLocked']" icon="pi pi-lock-open" [outlined]="true" (onClick)="toggleLock('authors')" severity="success"></p-button>
|
||||
<p-button *ngIf="metadata['authorsLocked']" icon="pi pi-lock" [outlined]="true" (onClick)="toggleLock('authors')" severity="warn"></p-button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="flex flex-col gap-1 w-1/3">
|
||||
<label for="publisher">Publisher</label>
|
||||
<input pInputText id="publisher" formControlName="publisher" class="w-full"/>
|
||||
<div class="flex justify-between items-center gap-2">
|
||||
<input pInputText id="publisher" formControlName="publisher" class="w-full"/>
|
||||
<p-button *ngIf="!metadata['publisherLocked']" icon="pi pi-lock-open" [outlined]="true" (onClick)="toggleLock('publisher')" severity="success"></p-button>
|
||||
<p-button *ngIf="metadata['publisherLocked']" icon="pi pi-lock" [outlined]="true" (onClick)="toggleLock('publisher')" severity="warn"></p-button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Categories and Published Date -->
|
||||
<div class="flex flex-row w-full gap-4 mt-2 pb-1">
|
||||
<div class="flex flex-col gap-1 w-2/3">
|
||||
<label for="categories">Categories</label>
|
||||
<input pInputText id="categories" formControlName="categories" class="w-full"/>
|
||||
<div class="flex justify-between items-center gap-2">
|
||||
<input pInputText id="categories" formControlName="categories" class="w-full"/>
|
||||
<p-button *ngIf="!metadata['categoriesLocked']" icon="pi pi-lock-open" [outlined]="true" (onClick)="toggleLock('categories')" severity="success"></p-button>
|
||||
<p-button *ngIf="metadata['categoriesLocked']" icon="pi pi-lock" [outlined]="true" (onClick)="toggleLock('categories')" severity="warn"></p-button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="flex flex-col gap-1 w-1/3">
|
||||
<label for="publishedDate">Publish Date</label>
|
||||
<input pInputText id="publishedDate" formControlName="publishedDate" class="w-full"/>
|
||||
<div class="flex justify-between items-center gap-2">
|
||||
<input pInputText id="publishedDate" formControlName="publishedDate" class="w-full"/>
|
||||
<p-button *ngIf="!metadata['publishedDateLocked']" icon="pi pi-lock-open" [outlined]="true" (onClick)="toggleLock('publishedDate')" severity="success"></p-button>
|
||||
<p-button *ngIf="metadata['publishedDateLocked']" icon="pi pi-lock" [outlined]="true" (onClick)="toggleLock('publishedDate')" severity="warn"></p-button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Language, ISBN 10, and ISBN 13 -->
|
||||
<!-- ISBN, Language, Review Count -->
|
||||
<div class="flex flex-row w-full gap-4 mt-2 pb-1">
|
||||
<div class="flex flex-col gap-1 w-1/3">
|
||||
<label for="language">Language</label>
|
||||
<input pInputText id="language" formControlName="language" class="w-full"/>
|
||||
<div class="flex justify-between items-center gap-2">
|
||||
<input pInputText id="language" formControlName="language" class="w-full"/>
|
||||
<p-button *ngIf="!metadata['languageLocked']" icon="pi pi-lock-open" [outlined]="true" (onClick)="toggleLock('language')" severity="success"></p-button>
|
||||
<p-button *ngIf="metadata['languageLocked']" icon="pi pi-lock" [outlined]="true" (onClick)="toggleLock('language')" severity="warn"></p-button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="flex flex-col gap-1 w-1/3">
|
||||
<label for="isbn10">ISBN 10</label>
|
||||
<input pInputText id="isbn10" formControlName="isbn10" class="w-full"/>
|
||||
<div class="flex justify-between items-center gap-2">
|
||||
<input pInputText id="isbn10" formControlName="isbn10" class="w-full"/>
|
||||
<p-button *ngIf="!metadata['isbn10Locked']" icon="pi pi-lock-open" [outlined]="true" (onClick)="toggleLock('isbn10')" severity="success"></p-button>
|
||||
<p-button *ngIf="metadata['isbn10Locked']" icon="pi pi-lock" [outlined]="true" (onClick)="toggleLock('isbn10')" severity="warn"></p-button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="flex flex-col gap-1 w-1/3">
|
||||
<label for="isbn13">ISBN 13</label>
|
||||
<input pInputText id="isbn13" formControlName="isbn13" class="w-full"/>
|
||||
<div class="flex justify-between items-center gap-2">
|
||||
<input pInputText id="isbn13" formControlName="isbn13" class="w-full"/>
|
||||
<p-button *ngIf="!metadata['isbn13Locked']" icon="pi pi-lock-open" [outlined]="true" (onClick)="toggleLock('isbn13')" severity="success"></p-button>
|
||||
<p-button *ngIf="metadata['isbn13Locked']" icon="pi pi-lock" [outlined]="true" (onClick)="toggleLock('isbn13')" severity="warn"></p-button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Review Count, Rating, Page Count -->
|
||||
<div class="flex flex-row w-full gap-4 mt-2 pb-1">
|
||||
<div class="flex flex-col gap-1 w-1/3">
|
||||
<label for="reviewCount">Review Count</label>
|
||||
<div class="flex justify-between items-center gap-2">
|
||||
<input pInputText id="reviewCount" formControlName="reviewCount" class="w-full"/>
|
||||
<p-button *ngIf="!metadata['reviewCountLocked']" icon="pi pi-lock-open" [outlined]="true" (onClick)="toggleLock('reviewCount')" severity="success"></p-button>
|
||||
<p-button *ngIf="metadata['reviewCountLocked']" icon="pi pi-lock" [outlined]="true" (onClick)="toggleLock('reviewCount')" severity="warn"></p-button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="flex flex-col gap-1 w-1/3">
|
||||
<label for="rating">Rating</label>
|
||||
<div class="flex justify-between items-center gap-2">
|
||||
<input pInputText id="rating" formControlName="rating" class="w-full"/>
|
||||
<p-button *ngIf="!metadata['ratingLocked']" icon="pi pi-lock-open" [outlined]="true" (onClick)="toggleLock('rating')" severity="success"></p-button>
|
||||
<p-button *ngIf="metadata['ratingLocked']" icon="pi pi-lock" [outlined]="true" (onClick)="toggleLock('rating')" severity="warn"></p-button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="flex flex-col gap-1 w-1/3">
|
||||
<label for="pageCount">Page Count</label>
|
||||
<div class="flex justify-between items-center gap-2">
|
||||
<input pInputText id="pageCount" formControlName="pageCount" class="w-full"/>
|
||||
<p-button *ngIf="!metadata['pageCountLocked']" icon="pi pi-lock-open" [outlined]="true" (onClick)="toggleLock('pageCount')" severity="success"></p-button>
|
||||
<p-button *ngIf="metadata['pageCountLocked']" icon="pi pi-lock" [outlined]="true" (onClick)="toggleLock('pageCount')" severity="warn"></p-button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="flex flex-row w-full gap-4 mt-2 pb-1">
|
||||
<div class="flex flex-col gap-1 w-1/3">
|
||||
<label for="reviewCount">Review Count</label>
|
||||
<input pInputText id="reviewCount" formControlName="reviewCount" class="w-full"/>
|
||||
</div>
|
||||
<div class="flex flex-col gap-1 w-1/3">
|
||||
<label for="rating">Rating</label>
|
||||
<input pInputText id="rating" formControlName="rating" class="w-full"/>
|
||||
</div>
|
||||
<div class="flex flex-col gap-1 w-1/3">
|
||||
<label for="pageCount">Page Count</label>
|
||||
<input pInputText id="pageCount" formControlName="pageCount" class="w-full"/>
|
||||
<div class="flex flex-col gap-1 w-full">
|
||||
<label for="description">Description</label>
|
||||
<div class="flex justify-between items-center gap-2">
|
||||
<textarea rows="12" pTextarea id="description" formControlName="description" class="w-full"></textarea>
|
||||
<p-button *ngIf="!metadata['descriptionLocked']" icon="pi pi-lock-open" [outlined]="true" (onClick)="toggleLock('description')" severity="success"></p-button>
|
||||
<p-button *ngIf="metadata['descriptionLocked']" icon="pi pi-lock" [outlined]="true" (onClick)="toggleLock('description')" severity="warn"></p-button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="flex flex-row w-full gap-4 mt-2 pb-1">
|
||||
<div class="flex flex-col gap-1 w-full">
|
||||
<label for="description">Description</label>
|
||||
<!--<p-editor class="w-full" formControlName="description" id="description" [style]="{ height: '18rem' }">
|
||||
<ng-template #header>
|
||||
<span class="ql-formats">
|
||||
<button type="button" class="ql-bold" aria-label="Bold"></button>
|
||||
<button type="button" class="ql-italic" aria-label="Italic"></button>
|
||||
<button type="button" class="ql-underline" aria-label="Underline"></button>
|
||||
</span>
|
||||
</ng-template>
|
||||
</p-editor>-->
|
||||
<textarea rows="12" pTextarea id="description" formControlName="description" class="w-full"></textarea>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="flex flex-col gap-x-4 mt-auto">
|
||||
|
||||
+80
-14
@@ -7,7 +7,6 @@ import {FormControl, FormGroup, FormsModule, ReactiveFormsModule} from '@angular
|
||||
import {Observable} from 'rxjs';
|
||||
import {BookMetadataCenterService} from '../book-metadata-center.service';
|
||||
import {AsyncPipe, NgIf} from '@angular/common';
|
||||
import {BookService} from '../../../book/service/book.service';
|
||||
import {MessageService} from 'primeng/api';
|
||||
import {MetadataService} from '../../service/metadata.service';
|
||||
import {BookMetadata} from '../../../book/model/book.model';
|
||||
@@ -17,7 +16,7 @@ import {UrlHelperService} from '../../../utilities/service/url-helper.service';
|
||||
selector: 'app-metadata-editor',
|
||||
standalone: true,
|
||||
templateUrl: './metadata-editor.component.html',
|
||||
styleUrl: './metadata-editor.component.scss',
|
||||
styleUrls: ['./metadata-editor.component.scss'],
|
||||
imports: [
|
||||
InputText,
|
||||
Textarea,
|
||||
@@ -32,7 +31,6 @@ import {UrlHelperService} from '../../../utilities/service/url-helper.service';
|
||||
export class MetadataEditorComponent implements OnInit {
|
||||
|
||||
private metadataCenterService = inject(BookMetadataCenterService);
|
||||
private bookService = inject(BookService);
|
||||
private messageService = inject(MessageService);
|
||||
private metadataService = inject(MetadataService);
|
||||
protected urlHelper = inject(UrlHelperService);
|
||||
@@ -56,6 +54,20 @@ export class MetadataEditorComponent implements OnInit {
|
||||
language: new FormControl(''),
|
||||
rating: new FormControl(''),
|
||||
reviewCount: new FormControl(''),
|
||||
|
||||
titleLocked: new FormControl(false),
|
||||
subtitleLocked: new FormControl(false),
|
||||
authorsLocked: new FormControl(false),
|
||||
categoriesLocked: new FormControl(false),
|
||||
publisherLocked: new FormControl(false),
|
||||
publishedDateLocked: new FormControl(false),
|
||||
isbn10Locked: new FormControl(false),
|
||||
isbn13Locked: new FormControl(false),
|
||||
descriptionLocked: new FormControl(false),
|
||||
pageCountLocked: new FormControl(false),
|
||||
languageLocked: new FormControl(false),
|
||||
ratingLocked: new FormControl(false),
|
||||
reviewCountLocked: new FormControl(false),
|
||||
});
|
||||
}
|
||||
|
||||
@@ -63,11 +75,12 @@ export class MetadataEditorComponent implements OnInit {
|
||||
this.bookMetadata$.subscribe((metadata) => {
|
||||
if (metadata) {
|
||||
this.currentBookId = metadata.bookId;
|
||||
|
||||
this.bookMetadataForm.setValue({
|
||||
title: metadata.title,
|
||||
subtitle: metadata.subtitle,
|
||||
authors: metadata.authors.map((author) => author.name).join(', '),
|
||||
categories: metadata.categories.map((category) => category.name).join(', '),
|
||||
authors: metadata.authors.map((author) => author.name).sort().join(', '),
|
||||
categories: metadata.categories.map((category) => category.name).sort().join(', '),
|
||||
publisher: metadata.publisher,
|
||||
publishedDate: metadata.publishedDate,
|
||||
isbn10: metadata.isbn10,
|
||||
@@ -76,13 +89,41 @@ export class MetadataEditorComponent implements OnInit {
|
||||
pageCount: metadata.pageCount == 0 ? null : metadata.pageCount,
|
||||
language: metadata.language,
|
||||
rating: metadata.rating,
|
||||
reviewCount: metadata.reviewCount
|
||||
reviewCount: metadata.reviewCount,
|
||||
|
||||
titleLocked: metadata.titleLocked || false,
|
||||
subtitleLocked: metadata.subtitleLocked || false,
|
||||
authorsLocked: metadata.authorsLocked || false,
|
||||
categoriesLocked: metadata.categoriesLocked || false,
|
||||
publisherLocked: metadata.publisherLocked || false,
|
||||
publishedDateLocked: metadata.publishedDateLocked || false,
|
||||
isbn10Locked: metadata.isbn10Locked || false,
|
||||
isbn13Locked: metadata.isbn13Locked || false,
|
||||
descriptionLocked: metadata.descriptionLocked || false,
|
||||
pageCountLocked: metadata.pageCountLocked || false,
|
||||
languageLocked: metadata.languageLocked || false,
|
||||
ratingLocked: metadata.ratingLocked || false,
|
||||
reviewCountLocked: metadata.reviewCountLocked || false,
|
||||
});
|
||||
|
||||
if (metadata.titleLocked) this.bookMetadataForm.get('title')?.disable();
|
||||
if (metadata.subtitleLocked) this.bookMetadataForm.get('subtitle')?.disable();
|
||||
if (metadata.authorsLocked) this.bookMetadataForm.get('authors')?.disable();
|
||||
if (metadata.categoriesLocked) this.bookMetadataForm.get('categories')?.disable();
|
||||
if (metadata.publisherLocked) this.bookMetadataForm.get('publisher')?.disable();
|
||||
if (metadata.publishedDateLocked) this.bookMetadataForm.get('publishedDate')?.disable();
|
||||
if (metadata.languageLocked) this.bookMetadataForm.get('language')?.disable();
|
||||
if (metadata.isbn10Locked) this.bookMetadataForm.get('isbn10')?.disable();
|
||||
if (metadata.isbn13Locked) this.bookMetadataForm.get('isbn13')?.disable();
|
||||
if (metadata.reviewCountLocked) this.bookMetadataForm.get('reviewCount')?.disable();
|
||||
if (metadata.ratingLocked) this.bookMetadataForm.get('rating')?.disable();
|
||||
if (metadata.pageCountLocked) this.bookMetadataForm.get('pageCount')?.disable();
|
||||
if (metadata.descriptionLocked) this.bookMetadataForm.get('description')?.disable();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
onSave(): void {
|
||||
onSave(source: string): void {
|
||||
const updatedBookMetadata: BookMetadata = {
|
||||
bookId: this.currentBookId,
|
||||
title: this.bookMetadataForm.get('title')?.value,
|
||||
@@ -97,21 +138,46 @@ export class MetadataEditorComponent implements OnInit {
|
||||
pageCount: this.bookMetadataForm.get('pageCount')?.value,
|
||||
rating: this.bookMetadataForm.get('rating')?.value,
|
||||
reviewCount: this.bookMetadataForm.get('reviewCount')?.value,
|
||||
language: this.bookMetadataForm.get('language')?.value
|
||||
language: this.bookMetadataForm.get('language')?.value,
|
||||
|
||||
titleLocked: this.bookMetadataForm.get('titleLocked')?.value,
|
||||
subtitleLocked: this.bookMetadataForm.get('subtitleLocked')?.value,
|
||||
authorsLocked: this.bookMetadataForm.get('authorsLocked')?.value,
|
||||
categoriesLocked: this.bookMetadataForm.get('categoriesLocked')?.value,
|
||||
publisherLocked: this.bookMetadataForm.get('publisherLocked')?.value,
|
||||
publishedDateLocked: this.bookMetadataForm.get('publishedDateLocked')?.value,
|
||||
isbn10Locked: this.bookMetadataForm.get('isbn10Locked')?.value,
|
||||
isbn13Locked: this.bookMetadataForm.get('isbn13Locked')?.value,
|
||||
descriptionLocked: this.bookMetadataForm.get('descriptionLocked')?.value,
|
||||
pageCountLocked: this.bookMetadataForm.get('pageCountLocked')?.value,
|
||||
languageLocked: this.bookMetadataForm.get('languageLocked')?.value,
|
||||
ratingLocked: this.bookMetadataForm.get('ratingLocked')?.value,
|
||||
reviewCountLocked: this.bookMetadataForm.get('reviewCountLocked')?.value,
|
||||
};
|
||||
|
||||
this.metadataService.updateBookMetadata(this.currentBookId, updatedBookMetadata).subscribe({
|
||||
next: () => {
|
||||
this.messageService.add({severity: 'info', summary: 'Success', detail: 'Book metadata updated'});
|
||||
this.metadataCenterService.emit(updatedBookMetadata);
|
||||
next: (response) => {
|
||||
if (source === 'saveButton') {
|
||||
this.messageService.add({severity: 'info', summary: 'Success', detail: 'Book metadata updated'});
|
||||
}
|
||||
this.metadataCenterService.emit(response);
|
||||
},
|
||||
error: () => {
|
||||
this.messageService.add({severity: 'error', summary: 'Error', detail: 'Failed to update book metadata'});
|
||||
}
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
coverImageSrc(bookId: number): string {
|
||||
return this.bookService.getBookCoverUrl(bookId);
|
||||
toggleLock(field: string): void {
|
||||
const isLocked = this.bookMetadataForm.get(field + 'Locked')?.value;
|
||||
const updatedLockedState = !isLocked;
|
||||
this.bookMetadataForm.get(field + 'Locked')?.setValue(updatedLockedState);
|
||||
if (updatedLockedState) {
|
||||
this.bookMetadataForm.get(field)?.disable();
|
||||
} else {
|
||||
this.bookMetadataForm.get(field)?.enable();
|
||||
}
|
||||
this.onSave('lock');
|
||||
}
|
||||
|
||||
closeDialog() {
|
||||
|
||||
+1
-1
@@ -55,7 +55,7 @@ export class MetadataSearcherComponent implements OnInit {
|
||||
}));
|
||||
}
|
||||
}));
|
||||
this.onSubmit();
|
||||
//this.onSubmit();
|
||||
}
|
||||
|
||||
get isSearchEnabled(): boolean {
|
||||
|
||||
@@ -24,6 +24,20 @@ export class MetadataService {
|
||||
return this.http.post<FetchedMetadata[]>(`${this.url}/${bookId}`, request);
|
||||
}
|
||||
|
||||
updatedMetadataFieldLock(bookId: number, field: string, isLocked: boolean): Observable<any> {
|
||||
const requestPayload = {
|
||||
bookId: bookId,
|
||||
field: field,
|
||||
isLocked: isLocked
|
||||
};
|
||||
return this.http.put<BookMetadata>(`${this.url}/lock`, requestPayload).pipe(
|
||||
map(updatedMetadata => {
|
||||
this.bookService.handleBookMetadataUpdate(bookId, updatedMetadata);
|
||||
return updatedMetadata;
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
updateBookMetadata(bookId: number, bookMetadata: BookMetadata): Observable<BookMetadata> {
|
||||
return this.http.put<BookMetadata>(`${this.url}/${bookId}`, bookMetadata).pipe(
|
||||
map(updatedMetadata => {
|
||||
|
||||
Reference in New Issue
Block a user