feat(read-status): Add Read Status tracking and filtering support
- Introduced `ReadStatus` enum and added `readStatus` field to `BookEntity` - Updated database schema with Flyway migration to store read status - Extended DTOs and backend API to handle read status updates - Added `updateBookReadStatus()` in backend service and controller - Integrated read status in Angular: display, update, and toast feedback - Added read status filters and labels across book listing, sidebar filter, and viewer - Refactored `MetadataViewerComponent` and extracted read status UI logic - Simplified read status label resolution using a mapping function
This commit is contained in:
committed by
Aditya Chandel
parent
cd4e14c8ad
commit
6bfbff5d34
@@ -5,6 +5,7 @@ import com.adityachandel.booklore.model.dto.Book;
|
||||
import com.adityachandel.booklore.model.dto.BookRecommendation;
|
||||
import com.adityachandel.booklore.model.dto.BookViewerSettings;
|
||||
import com.adityachandel.booklore.model.dto.request.ReadProgressRequest;
|
||||
import com.adityachandel.booklore.model.dto.request.ReadStatusUpdateRequest;
|
||||
import com.adityachandel.booklore.model.dto.request.ShelvesAssignmentRequest;
|
||||
import com.adityachandel.booklore.model.dto.response.BookDeletionResponse;
|
||||
import com.adityachandel.booklore.service.metadata.MetadataBackupRestoreService;
|
||||
@@ -112,4 +113,11 @@ public class BookController {
|
||||
public ResponseEntity<List<BookRecommendation>> getRecommendations(@PathVariable Long id, @RequestParam(defaultValue = "25") @Max(25) @Min(1) int limit) {
|
||||
return ResponseEntity.ok(bookRecommendationService.getRecommendations(id, limit));
|
||||
}
|
||||
|
||||
@PutMapping("/{bookId}/read-status")
|
||||
@CheckBookAccess(bookIdParam = "bookId")
|
||||
public ResponseEntity<Void> updateReadStatus(@PathVariable long bookId, @RequestBody @Valid ReadStatusUpdateRequest request) {
|
||||
bookService.updateReadStatus(bookId, request.status());
|
||||
return ResponseEntity.noContent().build();
|
||||
}
|
||||
}
|
||||
@@ -27,4 +27,5 @@ public class Book {
|
||||
private EpubProgress epubProgress;
|
||||
private CbxProgress cbxProgress;
|
||||
private Set<Shelf> shelves;
|
||||
private String readStatus;
|
||||
}
|
||||
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
package com.adityachandel.booklore.model.dto.request;
|
||||
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
|
||||
public record ReadStatusUpdateRequest(@NotBlank String status) {}
|
||||
@@ -3,6 +3,7 @@ package com.adityachandel.booklore.model.entity;
|
||||
import com.adityachandel.booklore.convertor.BookRecommendationIdsListConverter;
|
||||
import com.adityachandel.booklore.model.dto.BookRecommendationLite;
|
||||
import com.adityachandel.booklore.model.enums.BookFileType;
|
||||
import com.adityachandel.booklore.model.enums.ReadStatus;
|
||||
import jakarta.persistence.*;
|
||||
import lombok.*;
|
||||
|
||||
@@ -40,6 +41,10 @@ public class BookEntity {
|
||||
@Column(name = "metadata_match_score")
|
||||
private Float metadataMatchScore;
|
||||
|
||||
@Enumerated(EnumType.STRING)
|
||||
@Column(name = "read_status")
|
||||
private ReadStatus readStatus;
|
||||
|
||||
@OneToOne(mappedBy = "book", cascade = CascadeType.ALL, orphanRemoval = true, fetch = FetchType.LAZY)
|
||||
private BookMetadataEntity metadata;
|
||||
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
package com.adityachandel.booklore.model.enums;
|
||||
|
||||
public enum ReadStatus {
|
||||
UNREAD,
|
||||
READING,
|
||||
RE_READING,
|
||||
READ,
|
||||
PARTIALLY_READ,
|
||||
PAUSED,
|
||||
WONT_READ,
|
||||
ABANDONED
|
||||
}
|
||||
@@ -8,12 +8,15 @@ import com.adityachandel.booklore.model.dto.request.ReadProgressRequest;
|
||||
import com.adityachandel.booklore.model.dto.response.BookDeletionResponse;
|
||||
import com.adityachandel.booklore.model.entity.*;
|
||||
import com.adityachandel.booklore.model.enums.BookFileType;
|
||||
import com.adityachandel.booklore.model.enums.ReadStatus;
|
||||
import com.adityachandel.booklore.repository.*;
|
||||
import com.adityachandel.booklore.service.appsettings.AppSettingService;
|
||||
import com.adityachandel.booklore.util.FileService;
|
||||
import com.adityachandel.booklore.util.FileUtils;
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.EnumUtils;
|
||||
import org.springframework.core.io.ByteArrayResource;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.core.io.UrlResource;
|
||||
@@ -374,4 +377,11 @@ public class BookService {
|
||||
? ResponseEntity.ok(response)
|
||||
: ResponseEntity.status(HttpStatus.MULTI_STATUS).body(response);
|
||||
}
|
||||
|
||||
public void updateReadStatus(long bookId, @NotBlank String status) {
|
||||
BookEntity bookEntity = bookRepository.findById(bookId).orElseThrow(() -> ApiError.BOOK_NOT_FOUND.createException(bookId));
|
||||
ReadStatus readStatus = EnumUtils.getEnumIgnoreCase(ReadStatus.class, status);
|
||||
bookEntity.setReadStatus(readStatus);
|
||||
bookRepository.save(bookEntity);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
ALTER TABLE book
|
||||
ADD COLUMN read_status VARCHAR(20) DEFAULT 'UNREAD';
|
||||
Reference in New Issue
Block a user