show session numbers in book (#2696)

This commit is contained in:
WorldTeacher
2026-02-11 18:22:01 +01:00
committed by GitHub
parent aac8246bcf
commit 7e6ad212b0
4 changed files with 16 additions and 24 deletions

View File

@@ -37,8 +37,11 @@ public class ReadingSessionController {
@ApiResponse(responseCode = "404", description = "Book not found")
})
@GetMapping("/book/{bookId}")
public ResponseEntity<Page<ReadingSessionResponse>> getReadingSessionsForBook(@PathVariable Long bookId, @RequestParam(defaultValue = "0") int page) {
Page<ReadingSessionResponse> sessions = readingSessionService.getReadingSessionsForBook(bookId, page);
public ResponseEntity<Page<ReadingSessionResponse>> getReadingSessionsForBook(
@PathVariable Long bookId,
@RequestParam(defaultValue = "0") int page,
@RequestParam(defaultValue = "5") int size) {
Page<ReadingSessionResponse> sessions = readingSessionService.getReadingSessionsForBook(bookId, page, size);
return ResponseEntity.ok(sessions);
}
}

View File

@@ -244,13 +244,13 @@ public class ReadingSessionService {
}
@Transactional(readOnly = true)
public Page<ReadingSessionResponse> getReadingSessionsForBook(Long bookId, int page) {
public Page<ReadingSessionResponse> getReadingSessionsForBook(Long bookId, int page, int size) {
BookLoreUser authenticatedUser = authenticationService.getAuthenticatedUser();
Long userId = authenticatedUser.getId();
bookRepository.findById(bookId).orElseThrow(() -> ApiError.BOOK_NOT_FOUND.createException(bookId));
Pageable pageable = PageRequest.of(page, 5);
Pageable pageable = PageRequest.of(page, size);
Page<ReadingSessionEntity> sessions = readingSessionRepository.findByUserIdAndBookId(userId, bookId, pageable);
return sessions.map(session -> ReadingSessionResponse.builder()