fix(books): add missing book metadata fields (#1032)
This commit is contained in:
@@ -28,16 +28,37 @@ public class AppBookSummary {
|
||||
private Instant addedOn;
|
||||
private Instant lastReadTime;
|
||||
private Float readProgress;
|
||||
private Long primaryFileId;
|
||||
private String primaryFileType;
|
||||
private String primaryFileName;
|
||||
private Instant coverUpdatedOn;
|
||||
private Instant audiobookCoverUpdatedOn;
|
||||
private Boolean isPhysical;
|
||||
|
||||
// Metadata for filtering
|
||||
private String publisher;
|
||||
private List<String> categories;
|
||||
private List<String> tags;
|
||||
private List<String> moods;
|
||||
private String language;
|
||||
private String narrator;
|
||||
private String isbn13;
|
||||
private String isbn10;
|
||||
private LocalDate publishedDate;
|
||||
private Integer pageCount;
|
||||
private Integer ageRating;
|
||||
private String contentRating;
|
||||
private Float metadataMatchScore;
|
||||
private Long fileSizeKb;
|
||||
private Double amazonRating;
|
||||
private Integer amazonReviewCount;
|
||||
private Double goodreadsRating;
|
||||
private Integer goodreadsReviewCount;
|
||||
private Double hardcoverRating;
|
||||
private Integer hardcoverReviewCount;
|
||||
private Double ranobedbRating;
|
||||
private Double lubimyczytacRating;
|
||||
private Double audibleRating;
|
||||
private Integer audibleReviewCount;
|
||||
private Boolean allMetadataLocked;
|
||||
}
|
||||
|
||||
@@ -31,16 +31,37 @@ public interface AppBookMapper {
|
||||
@Mapping(target = "addedOn", source = "book.addedOn")
|
||||
@Mapping(target = "lastReadTime", source = "progress.lastReadTime")
|
||||
@Mapping(target = "readProgress", source = "progress", qualifiedByName = "mapReadProgress")
|
||||
@Mapping(target = "primaryFileId", source = "book", qualifiedByName = "mapPrimaryFileId")
|
||||
@Mapping(target = "primaryFileType", source = "book", qualifiedByName = "mapPrimaryFileType")
|
||||
@Mapping(target = "primaryFileName", source = "book", qualifiedByName = "mapPrimaryFileName")
|
||||
@Mapping(target = "coverUpdatedOn", source = "book.metadata.coverUpdatedOn")
|
||||
@Mapping(target = "audiobookCoverUpdatedOn", source = "book.metadata.audiobookCoverUpdatedOn")
|
||||
@Mapping(target = "isPhysical", source = "book.isPhysical")
|
||||
@Mapping(target = "publisher", source = "book.metadata.publisher")
|
||||
@Mapping(target = "categories", source = "book.metadata.categories", qualifiedByName = "mapCategoryNames")
|
||||
@Mapping(target = "tags", source = "book.metadata.tags", qualifiedByName = "mapTagNames")
|
||||
@Mapping(target = "moods", source = "book.metadata.moods", qualifiedByName = "mapMoodNames")
|
||||
@Mapping(target = "language", source = "book.metadata.language")
|
||||
@Mapping(target = "narrator", source = "book.metadata.narrator")
|
||||
@Mapping(target = "isbn13", source = "book.metadata.isbn13")
|
||||
@Mapping(target = "isbn10", source = "book.metadata.isbn10")
|
||||
@Mapping(target = "publishedDate", source = "book.metadata.publishedDate")
|
||||
@Mapping(target = "pageCount", source = "book.metadata.pageCount")
|
||||
@Mapping(target = "ageRating", source = "book.metadata.ageRating")
|
||||
@Mapping(target = "contentRating", source = "book.metadata.contentRating")
|
||||
@Mapping(target = "metadataMatchScore", source = "book.metadataMatchScore")
|
||||
@Mapping(target = "fileSizeKb", source = "book", qualifiedByName = "mapFileSizeKb")
|
||||
@Mapping(target = "amazonRating", source = "book.metadata.amazonRating")
|
||||
@Mapping(target = "amazonReviewCount", source = "book.metadata.amazonReviewCount")
|
||||
@Mapping(target = "goodreadsRating", source = "book.metadata.goodreadsRating")
|
||||
@Mapping(target = "goodreadsReviewCount", source = "book.metadata.goodreadsReviewCount")
|
||||
@Mapping(target = "hardcoverRating", source = "book.metadata.hardcoverRating")
|
||||
@Mapping(target = "hardcoverReviewCount", source = "book.metadata.hardcoverReviewCount")
|
||||
@Mapping(target = "ranobedbRating", source = "book.metadata.ranobedbRating")
|
||||
@Mapping(target = "lubimyczytacRating", source = "book.metadata.lubimyczytacRating")
|
||||
@Mapping(target = "audibleRating", source = "book.metadata.audibleRating")
|
||||
@Mapping(target = "audibleReviewCount", source = "book.metadata.audibleReviewCount")
|
||||
@Mapping(target = "allMetadataLocked", source = "book.metadata", qualifiedByName = "mapAllMetadataLocked")
|
||||
AppBookSummary toSummary(BookEntity book, UserBookProgressEntity progress);
|
||||
|
||||
@Mapping(target = "id", source = "book.id")
|
||||
@@ -114,6 +135,39 @@ public interface AppBookMapper {
|
||||
.collect(Collectors.toSet());
|
||||
}
|
||||
|
||||
@Named("mapCategoryNames")
|
||||
default List<String> mapCategoryNames(Set<CategoryEntity> categories) {
|
||||
if (categories == null || categories.isEmpty()) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
return categories.stream()
|
||||
.map(CategoryEntity::getName)
|
||||
.sorted()
|
||||
.toList();
|
||||
}
|
||||
|
||||
@Named("mapTagNames")
|
||||
default List<String> mapTagNames(Set<TagEntity> tags) {
|
||||
if (tags == null || tags.isEmpty()) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
return tags.stream()
|
||||
.map(TagEntity::getName)
|
||||
.sorted()
|
||||
.toList();
|
||||
}
|
||||
|
||||
@Named("mapMoodNames")
|
||||
default List<String> mapMoodNames(Set<MoodEntity> moods) {
|
||||
if (moods == null || moods.isEmpty()) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
return moods.stream()
|
||||
.map(MoodEntity::getName)
|
||||
.sorted()
|
||||
.toList();
|
||||
}
|
||||
|
||||
@Named("mapThumbnailUrl")
|
||||
default String mapThumbnailUrl(BookEntity book) {
|
||||
if (book == null || book.getId() == null) {
|
||||
@@ -129,6 +183,11 @@ public interface AppBookMapper {
|
||||
return primaryFile != null ? primaryFile.getFileSizeKb() : null;
|
||||
}
|
||||
|
||||
@Named("mapAllMetadataLocked")
|
||||
default Boolean mapAllMetadataLocked(BookMetadataEntity metadata) {
|
||||
return metadata != null && metadata.areAllFieldsLocked();
|
||||
}
|
||||
|
||||
@Named("mapShelves")
|
||||
default List<AppShelfSummary> mapShelves(Set<ShelfEntity> shelves) {
|
||||
if (shelves == null || shelves.isEmpty()) {
|
||||
@@ -271,6 +330,24 @@ public interface AppBookMapper {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Named("mapPrimaryFileId")
|
||||
default Long mapPrimaryFileId(BookEntity book) {
|
||||
if (book == null) {
|
||||
return null;
|
||||
}
|
||||
BookFileEntity primaryFile = book.getPrimaryBookFile();
|
||||
return primaryFile != null ? primaryFile.getId() : null;
|
||||
}
|
||||
|
||||
@Named("mapPrimaryFileName")
|
||||
default String mapPrimaryFileName(BookEntity book) {
|
||||
if (book == null) {
|
||||
return null;
|
||||
}
|
||||
BookFileEntity primaryFile = book.getPrimaryBookFile();
|
||||
return primaryFile != null ? primaryFile.getFileName() : null;
|
||||
}
|
||||
|
||||
@Named("mapFileTypes")
|
||||
default List<String> mapFileTypes(BookEntity book) {
|
||||
if (book == null || book.getBookFiles() == null || book.getBookFiles().isEmpty()) {
|
||||
|
||||
@@ -246,6 +246,9 @@ export class BookBrowserComponent implements AfterViewInit {
|
||||
case 'amazonRating': scopeFilters.amazonRating = strValues; break;
|
||||
case 'goodreadsRating': scopeFilters.goodreadsRating = strValues; break;
|
||||
case 'hardcoverRating': scopeFilters.hardcoverRating = strValues; break;
|
||||
case 'lubimyczytacRating': scopeFilters.lubimyczytacRating = strValues; break;
|
||||
case 'ranobedbRating': scopeFilters.ranobedbRating = strValues; break;
|
||||
case 'audibleRating': scopeFilters.audibleRating = strValues; break;
|
||||
case 'pageCount': scopeFilters.pageCount = strValues; break;
|
||||
case 'shelfStatus':
|
||||
scopeFilters.shelfStatus = strValues;
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import {BookType} from './book.model';
|
||||
|
||||
export interface AppPageResponse<T> {
|
||||
content: T[];
|
||||
page: number;
|
||||
@@ -21,16 +23,37 @@ export interface AppBookSummary {
|
||||
addedOn: string | null;
|
||||
lastReadTime: string | null;
|
||||
readProgress: number | null;
|
||||
primaryFileType: string | null;
|
||||
primaryFileId: number | null;
|
||||
primaryFileType: BookType | null;
|
||||
primaryFileName: string | null;
|
||||
coverUpdatedOn: string | null;
|
||||
audiobookCoverUpdatedOn: string | null;
|
||||
isPhysical: boolean | null;
|
||||
publisher: string | null;
|
||||
categories: string[] | null;
|
||||
tags: string[] | null;
|
||||
moods: string[] | null;
|
||||
language: string | null;
|
||||
narrator: string | null;
|
||||
isbn13: string | null;
|
||||
isbn10: string | null;
|
||||
publishedDate: string | null;
|
||||
pageCount: number | null;
|
||||
ageRating: number | null;
|
||||
contentRating: string | null;
|
||||
metadataMatchScore: number | null;
|
||||
fileSizeKb: number | null;
|
||||
amazonRating: number | null;
|
||||
amazonReviewCount: number | null;
|
||||
goodreadsRating: number | null;
|
||||
goodreadsReviewCount: number | null;
|
||||
hardcoverRating: number | null;
|
||||
hardcoverReviewCount: number | null;
|
||||
ranobedbRating: number | null;
|
||||
lubimyczytacRating: number | null;
|
||||
audibleRating: number | null;
|
||||
audibleReviewCount: number | null;
|
||||
allMetadataLocked: boolean | null;
|
||||
}
|
||||
|
||||
export interface AppFilterOptions {
|
||||
|
||||
@@ -11,7 +11,7 @@ import {
|
||||
AppFilterOptions,
|
||||
AppPageResponse,
|
||||
} from '../model/app-book.model';
|
||||
import {Book, BookType, ReadStatus} from '../model/book.model';
|
||||
import {Book, BookFile, BookType, ReadStatus} from '../model/book.model';
|
||||
|
||||
const PAGE_SIZE = 50;
|
||||
|
||||
@@ -62,16 +62,6 @@ export class AppBooksApiService {
|
||||
const data = this.booksQuery.data();
|
||||
if (!data) return [];
|
||||
return data.pages.flatMap(page => page.content.map(summaryToBook));
|
||||
}, {
|
||||
equal: (a, b) => {
|
||||
if (a.length !== b.length) return false;
|
||||
for (let i = 0; i < a.length; i++) {
|
||||
if (a[i].id !== b[i].id) return false;
|
||||
if (a[i].metadata?.coverUpdatedOn !== b[i].metadata?.coverUpdatedOn) return false;
|
||||
if (a[i].metadata?.audiobookCoverUpdatedOn !== b[i].metadata?.audiobookCoverUpdatedOn) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
});
|
||||
|
||||
readonly totalElements = computed(() => {
|
||||
@@ -249,18 +239,35 @@ function summaryToBook(summary: AppBookSummary): Book {
|
||||
bookId: summary.id,
|
||||
title: summary.title,
|
||||
authors: summary.authors ?? [],
|
||||
publisher: summary.publisher ?? undefined,
|
||||
seriesName: summary.seriesName,
|
||||
seriesNumber: summary.seriesNumber,
|
||||
categories: summary.categories ?? [],
|
||||
tags: summary.tags ?? [],
|
||||
moods: summary.moods ?? [],
|
||||
language: summary.language ?? undefined,
|
||||
narrator: summary.narrator ?? undefined,
|
||||
isbn13: summary.isbn13 ?? undefined,
|
||||
isbn10: summary.isbn10 ?? undefined,
|
||||
coverUpdatedOn: summary.coverUpdatedOn,
|
||||
audiobookCoverUpdatedOn: summary.audiobookCoverUpdatedOn,
|
||||
publishedDate: summary.publishedDate ?? undefined,
|
||||
pageCount: summary.pageCount,
|
||||
ageRating: summary.ageRating,
|
||||
contentRating: summary.contentRating,
|
||||
amazonRating: summary.amazonRating,
|
||||
amazonReviewCount: summary.amazonReviewCount,
|
||||
goodreadsRating: summary.goodreadsRating,
|
||||
goodreadsReviewCount: summary.goodreadsReviewCount,
|
||||
hardcoverRating: summary.hardcoverRating,
|
||||
hardcoverReviewCount: summary.hardcoverReviewCount,
|
||||
ranobedbRating: summary.ranobedbRating,
|
||||
lubimyczytacRating: summary.lubimyczytacRating,
|
||||
audibleRating: summary.audibleRating,
|
||||
audibleReviewCount: summary.audibleReviewCount,
|
||||
allMetadataLocked: summary.allMetadataLocked ?? false,
|
||||
},
|
||||
primaryFile: summary.primaryFileType
|
||||
? {bookType: summary.primaryFileType as BookType, extension: summary.primaryFileType.toLowerCase()}
|
||||
: null,
|
||||
primaryFile: summaryToPrimaryFile(summary),
|
||||
pdfProgress: summary.readProgress != null
|
||||
? {page: 0, percentage: summary.readProgress}
|
||||
: null,
|
||||
@@ -269,3 +276,33 @@ function summaryToBook(summary: AppBookSummary): Book {
|
||||
shelves: [],
|
||||
} as unknown as Book;
|
||||
}
|
||||
|
||||
function summaryToPrimaryFile(summary: AppBookSummary): Partial<BookFile> | null {
|
||||
if (!summary.primaryFileType) return null;
|
||||
|
||||
const primaryFile: Partial<BookFile> = {
|
||||
bookId: summary.id,
|
||||
bookType: summary.primaryFileType,
|
||||
extension: summaryToPrimaryFileExtension(summary, summary.primaryFileType),
|
||||
fileSizeKb: summary.fileSizeKb ?? undefined,
|
||||
fileName: summary.primaryFileName ?? undefined,
|
||||
};
|
||||
|
||||
if (summary.primaryFileId != null) {
|
||||
primaryFile.id = summary.primaryFileId;
|
||||
}
|
||||
|
||||
return primaryFile;
|
||||
}
|
||||
|
||||
function summaryToPrimaryFileExtension(summary: AppBookSummary, bookType: BookType): string | undefined {
|
||||
const fileName = summary.primaryFileName;
|
||||
if (fileName) {
|
||||
const dotIndex = fileName.lastIndexOf('.');
|
||||
if (dotIndex >= 0 && dotIndex < fileName.length - 1) {
|
||||
return fileName.slice(dotIndex + 1).toLowerCase();
|
||||
}
|
||||
}
|
||||
|
||||
return bookType.toLowerCase();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user