Fix updating finished date on physical books throwing unsupported book type error (#2949)
This commit is contained in:
+30
-21
@@ -209,36 +209,45 @@ public class ReadingProgressService {
|
||||
progress.setBook(book);
|
||||
progress.setLastReadTime(now);
|
||||
|
||||
Float percentage;
|
||||
Float percentage = null;
|
||||
|
||||
if (request.getFileProgress() != null) {
|
||||
BookFileProgress fileProgress = request.getFileProgress();
|
||||
percentage = fileProgress.progressPercent();
|
||||
boolean hasProgressData = request.getFileProgress() != null
|
||||
|| request.getEpubProgress() != null
|
||||
|| request.getPdfProgress() != null
|
||||
|| request.getCbxProgress() != null
|
||||
|| request.getAudiobookProgress() != null;
|
||||
|
||||
saveToUserBookFileProgress(userEntity, fileProgress, now);
|
||||
if (hasProgressData) {
|
||||
if (request.getFileProgress() != null) {
|
||||
BookFileProgress fileProgress = request.getFileProgress();
|
||||
percentage = fileProgress.progressPercent();
|
||||
|
||||
BookFileEntity bookFile = bookFileRepository.findById(fileProgress.bookFileId())
|
||||
.orElseThrow(() -> ApiError.GENERIC_NOT_FOUND.createException("Book file not found"));
|
||||
updateProgressFromFileProgress(progress, bookFile.getBookType(), fileProgress);
|
||||
} else {
|
||||
BookFileEntity primaryFile = book.getPrimaryBookFile();
|
||||
if (primaryFile == null) {
|
||||
throw ApiError.UNSUPPORTED_BOOK_TYPE.createException();
|
||||
saveToUserBookFileProgress(userEntity, fileProgress, now);
|
||||
|
||||
BookFileEntity bookFile = bookFileRepository.findById(fileProgress.bookFileId())
|
||||
.orElseThrow(() -> ApiError.GENERIC_NOT_FOUND.createException("Book file not found"));
|
||||
updateProgressFromFileProgress(progress, bookFile.getBookType(), fileProgress);
|
||||
} else {
|
||||
BookFileEntity primaryFile = book.getPrimaryBookFile();
|
||||
if (primaryFile == null) {
|
||||
throw ApiError.UNSUPPORTED_BOOK_TYPE.createException();
|
||||
}
|
||||
percentage = updateProgressByBookType(progress, primaryFile.getBookType(), request);
|
||||
|
||||
if (percentage != null) {
|
||||
saveToUserBookFileProgressFromLegacy(userEntity, primaryFile, progress, now);
|
||||
}
|
||||
}
|
||||
percentage = updateProgressByBookType(progress, primaryFile.getBookType(), request);
|
||||
|
||||
if (percentage != null) {
|
||||
saveToUserBookFileProgressFromLegacy(userEntity, primaryFile, progress, now);
|
||||
progress.setReadStatus(calculateReadStatus(percentage, progress.getReadStatus()));
|
||||
BookFileEntity primaryFile = book.getPrimaryBookFile();
|
||||
if (primaryFile != null) {
|
||||
setProgressPercent(progress, primaryFile.getBookType(), percentage);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (percentage != null) {
|
||||
progress.setReadStatus(calculateReadStatus(percentage, progress.getReadStatus()));
|
||||
BookFileEntity primaryFile = book.getPrimaryBookFile();
|
||||
if (primaryFile != null) {
|
||||
setProgressPercent(progress, primaryFile.getBookType(), percentage);
|
||||
}
|
||||
}
|
||||
if (request.getDateFinished() != null) {
|
||||
progress.setDateFinished(request.getDateFinished());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user