Add ability to reset reading progress for a book
This commit is contained in:
committed by
Aditya Chandel
parent
5afe0a1b0a
commit
ceac960943
@@ -124,4 +124,11 @@ public class BookController {
|
||||
bookService.updateReadStatus(bookId, request.status());
|
||||
return ResponseEntity.noContent().build();
|
||||
}
|
||||
|
||||
@PostMapping("/{bookId}/reset-progress")
|
||||
@CheckBookAccess(bookIdParam = "bookId")
|
||||
public ResponseEntity<Book> resetProgress(@PathVariable long bookId) {
|
||||
Book book = bookService.resetProgress(bookId);
|
||||
return ResponseEntity.ok(book);
|
||||
}
|
||||
}
|
||||
@@ -277,6 +277,24 @@ public class BookService {
|
||||
return book;
|
||||
}
|
||||
|
||||
public Book resetProgress(long bookId) {
|
||||
BookLoreUser user = authenticationService.getAuthenticatedUser();
|
||||
BookEntity bookEntity = bookRepository.findById(bookId).orElseThrow(() -> ApiError.BOOK_NOT_FOUND.createException(bookId));
|
||||
|
||||
UserBookProgressEntity progress = userBookProgressRepository.findByUserIdAndBookId(user.getId(), bookId).orElse(new UserBookProgressEntity());
|
||||
progress.setBook(bookEntity);
|
||||
progress.setReadStatus(null);
|
||||
progress.setLastReadTime(null);
|
||||
progress.setPdfProgress(null);
|
||||
progress.setPdfProgressPercent(null);
|
||||
progress.setEpubProgress(null);
|
||||
progress.setEpubProgressPercent(null);
|
||||
progress.setCbxProgress(null);
|
||||
progress.setCbxProgressPercent(null);
|
||||
userBookProgressRepository.save(progress);
|
||||
return bookMapper.toBook(bookEntity);
|
||||
}
|
||||
|
||||
|
||||
@Transactional
|
||||
public List<Book> assignShelvesToBooks(Set<Long> bookIds, Set<Long> shelfIdsToAssign, Set<Long> shelfIdsToUnassign) {
|
||||
|
||||
Reference in New Issue
Block a user