mirror of
https://github.com/booklore-app/booklore.git
synced 2026-02-18 00:17:53 +01:00
show session numbers in book (#2696)
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -12,17 +12,13 @@
|
||||
} @else {
|
||||
<p-table
|
||||
[value]="sessions"
|
||||
[lazy]="true"
|
||||
[paginator]="true"
|
||||
[rows]="rows"
|
||||
[totalRecords]="totalRecords"
|
||||
[loading]="loading"
|
||||
[first]="first"
|
||||
(onLazyLoad)="onPageChange($event)"
|
||||
[showCurrentPageReport]="true"
|
||||
[currentPageReportTemplate]="t('pageReport')"
|
||||
currentPageReportTemplate="Showing {first} to {last} of {totalRecords} sessions"
|
||||
class="p-datatable-sm">
|
||||
<ng-template #header>
|
||||
<ng-template pTemplate="header">
|
||||
<tr>
|
||||
<th>{{ t('headerSession') }}</th>
|
||||
<th>{{ t('headerType') }}</th>
|
||||
@@ -32,7 +28,7 @@
|
||||
<th>{{ t('headerLocation') }}</th>
|
||||
</tr>
|
||||
</ng-template>
|
||||
<ng-template #body let-session>
|
||||
<ng-template pTemplate="body" let-session>
|
||||
<tr>
|
||||
<td>
|
||||
<div class="session-time">
|
||||
|
||||
@@ -18,29 +18,29 @@ export class BookReadingSessionsComponent implements OnInit, OnChanges {
|
||||
private readonly t = inject(TranslocoService);
|
||||
|
||||
sessions: ReadingSessionResponse[] = [];
|
||||
totalRecords = 0;
|
||||
first = 0;
|
||||
rows = 5;
|
||||
loading = false;
|
||||
|
||||
get pageReportTemplate(): string {
|
||||
return this.t.translate('metadata.readingSessions.pageReport');
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
this.loadSessions();
|
||||
}
|
||||
|
||||
ngOnChanges(changes: SimpleChanges) {
|
||||
if (changes['bookId'] && !changes['bookId'].firstChange) {
|
||||
this.first = 0;
|
||||
this.loadSessions();
|
||||
}
|
||||
}
|
||||
|
||||
loadSessions(page: number = 0) {
|
||||
loadSessions() {
|
||||
this.loading = true;
|
||||
this.readingSessionService.getSessionsByBookId(this.bookId, page, this.rows)
|
||||
this.readingSessionService.getSessionsByBookId(this.bookId, 0, 9999)
|
||||
.subscribe({
|
||||
next: (response) => {
|
||||
this.sessions = response.content;
|
||||
this.totalRecords = response.totalElements;
|
||||
this.loading = false;
|
||||
},
|
||||
error: () => {
|
||||
@@ -49,13 +49,6 @@ export class BookReadingSessionsComponent implements OnInit, OnChanges {
|
||||
});
|
||||
}
|
||||
|
||||
onPageChange(event: { first?: number; rows?: number | null }): void {
|
||||
if (event.first === undefined || event.rows === undefined || event.rows === null) return;
|
||||
this.first = event.first;
|
||||
const page = Math.floor(event.first / event.rows);
|
||||
this.loadSessions(page);
|
||||
}
|
||||
|
||||
formatDuration(seconds: number): string {
|
||||
const hours = Math.floor(seconds / 3600);
|
||||
const minutes = Math.floor((seconds % 3600) / 60);
|
||||
|
||||
Reference in New Issue
Block a user