Add user specific book progress tracking and improve epub progress tracking
This commit is contained in:
committed by
Aditya Chandel
parent
8d8379e689
commit
c2960ad830
@@ -1,5 +1,6 @@
|
||||
package com.adityachandel.booklore.model.dto;
|
||||
|
||||
import com.adityachandel.booklore.model.dto.request.ReadProgressRequest;
|
||||
import com.adityachandel.booklore.model.enums.BookFileType;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import lombok.Data;
|
||||
@@ -20,7 +21,7 @@ public class Book {
|
||||
private Instant lastReadTime;
|
||||
private Instant addedOn;
|
||||
private BookMetadata metadata;
|
||||
private Integer pdfProgress;
|
||||
private String epubProgress;
|
||||
private PdfProgress pdfProgress;
|
||||
private EpubProgress epubProgress;
|
||||
private List<Shelf> shelves;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
package com.adityachandel.booklore.model.dto;
|
||||
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
|
||||
@Builder
|
||||
@Data
|
||||
public class EpubProgress {
|
||||
@NotNull
|
||||
String cfi;
|
||||
@NotNull
|
||||
Float percentage;
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package com.adityachandel.booklore.model.dto;
|
||||
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
|
||||
@Builder
|
||||
@Data
|
||||
public class PdfProgress {
|
||||
@NotNull
|
||||
Integer page;
|
||||
@NotNull
|
||||
Float percentage;
|
||||
}
|
||||
+4
-2
@@ -1,5 +1,7 @@
|
||||
package com.adityachandel.booklore.model.dto.request;
|
||||
|
||||
import com.adityachandel.booklore.model.dto.EpubProgress;
|
||||
import com.adityachandel.booklore.model.dto.PdfProgress;
|
||||
import jakarta.validation.constraints.AssertTrue;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.Data;
|
||||
@@ -8,8 +10,8 @@ import lombok.Data;
|
||||
public class ReadProgressRequest {
|
||||
@NotNull
|
||||
private Long bookId;
|
||||
private String epubProgress;
|
||||
private Integer pdfProgress;
|
||||
private EpubProgress epubProgress;
|
||||
private PdfProgress pdfProgress;
|
||||
|
||||
@AssertTrue(message = "Either epubProgress or pdfProgress must be provided")
|
||||
public boolean isProgressValid() {
|
||||
|
||||
+6
@@ -32,6 +32,12 @@ public class UserBookProgressEntity {
|
||||
@Column(name = "pdf_progress")
|
||||
private Integer pdfProgress;
|
||||
|
||||
@Column(name = "pdf_progress_percent")
|
||||
private Float pdfProgressPercent;
|
||||
|
||||
@Column(name = "epub_progress", length = 1000)
|
||||
private String epubProgress;
|
||||
|
||||
@Column(name = "epub_progress_percent")
|
||||
private Float epubProgressPercent;
|
||||
}
|
||||
|
||||
@@ -124,8 +124,19 @@ public class BooksService {
|
||||
|
||||
Book book = bookMapper.toBook(bookEntity);
|
||||
book.setLastReadTime(userProgress.getLastReadTime());
|
||||
book.setPdfProgress(userProgress.getPdfProgress());
|
||||
book.setEpubProgress(userProgress.getEpubProgress());
|
||||
|
||||
if (bookEntity.getBookType() == BookFileType.PDF) {
|
||||
book.setPdfProgress(PdfProgress.builder()
|
||||
.page(userProgress.getPdfProgress())
|
||||
.percentage(userProgress.getPdfProgressPercent())
|
||||
.build());
|
||||
}
|
||||
if (bookEntity.getBookType() == BookFileType.EPUB) {
|
||||
book.setEpubProgress(EpubProgress.builder()
|
||||
.cfi(userProgress.getEpubProgress())
|
||||
.percentage(userProgress.getEpubProgressPercent())
|
||||
.build());
|
||||
}
|
||||
book.setFilePath(FileUtils.getBookFullPath(bookEntity));
|
||||
|
||||
if (!withDescription) {
|
||||
@@ -157,8 +168,18 @@ public class BooksService {
|
||||
.orElse(new UserBookProgressEntity());
|
||||
Book book = bookMapper.toBookWithDescription(bookEntity, withDescription);
|
||||
book.setLastReadTime(userProgress.getLastReadTime());
|
||||
book.setPdfProgress(userProgress.getPdfProgress());
|
||||
book.setEpubProgress(userProgress.getEpubProgress());
|
||||
if (bookEntity.getBookType() == BookFileType.EPUB) {
|
||||
book.setEpubProgress(EpubProgress.builder()
|
||||
.cfi(userProgress.getEpubProgress())
|
||||
.percentage(userProgress.getEpubProgressPercent())
|
||||
.build());
|
||||
}
|
||||
if (bookEntity.getBookType() == BookFileType.PDF) {
|
||||
book.setPdfProgress(PdfProgress.builder()
|
||||
.page(userProgress.getPdfProgress())
|
||||
.percentage(userProgress.getPdfProgressPercent())
|
||||
.build());
|
||||
}
|
||||
book.setFilePath(FileUtils.getBookFullPath(bookEntity));
|
||||
return book;
|
||||
})
|
||||
@@ -210,9 +231,11 @@ public class BooksService {
|
||||
userBookProgress.setBook(book);
|
||||
userBookProgress.setLastReadTime(Instant.now());
|
||||
if (book.getBookType() == BookFileType.EPUB && request.getEpubProgress() != null) {
|
||||
userBookProgress.setEpubProgress(request.getEpubProgress());
|
||||
userBookProgress.setEpubProgress(request.getEpubProgress().getCfi());
|
||||
userBookProgress.setEpubProgressPercent(request.getEpubProgress().getPercentage());
|
||||
} else if (book.getBookType() == BookFileType.PDF && request.getPdfProgress() != null) {
|
||||
userBookProgress.setPdfProgress(request.getPdfProgress());
|
||||
userBookProgress.setPdfProgress(request.getPdfProgress().getPage());
|
||||
userBookProgress.setPdfProgressPercent(request.getPdfProgress().getPercentage());
|
||||
}
|
||||
userBookProgressRepository.save(userBookProgress);
|
||||
}
|
||||
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
ALTER TABLE user_book_progress
|
||||
ADD COLUMN pdf_progress_percent FLOAT NULL,
|
||||
ADD COLUMN epub_progress_percent FLOAT NULL;
|
||||
Reference in New Issue
Block a user