basic booking load behavior

This commit is contained in:
Roland Schneider
2025-12-16 15:31:45 +01:00
parent fe30561a40
commit c26abee957
6 changed files with 82 additions and 19 deletions

File diff suppressed because one or more lines are too long

View File

@@ -152,4 +152,20 @@ export class CalendarService {
return this.httpClient.patch(url, cancelBookingDto, requestOptions);
}
calendarControllerGetBookings(eventId: number, startTime: Date, observe?: 'body', options?: RequestOptions<'json'>): Observable<any>;
calendarControllerGetBookings(eventId: number, startTime: Date, observe?: 'response', options?: RequestOptions<'json'>): Observable<HttpResponse<any>>;
calendarControllerGetBookings(eventId: number, startTime: Date, observe?: 'events', options?: RequestOptions<'json'>): Observable<HttpEvent<any>>;
calendarControllerGetBookings(eventId: number, startTime: Date, observe?: 'body' | 'events' | 'response', options?: RequestOptions<'arraybuffer' | 'blob' | 'json' | 'text'>): Observable<any> {
const url = `${this.basePath}/api/calendar/bookings/${eventId}/${startTime}`;
const requestOptions: any = {
observe: observe as any,
reportProgress: options?.reportProgress,
withCredentials: options?.withCredentials,
context: this.createContextWithClientId(options?.context)
};
return this.httpClient.get(url, requestOptions);
}
}

View File

@@ -1,7 +1,11 @@
<h1>Foglalások</h1>
@for ( booking of bookings.value();track booking){
@if (bookings.isLoading()) {
<div>loading...</div>
} @else {
@for (booking of bookings.value()?.items; track booking) {
<div>
{{ booking }}
</div>
}
<rs-daisy-pagination [pageCount]="pageCount()" [activePage]="1" (onPaginate)="paginate($event)"></rs-daisy-pagination>
<rs-daisy-pagination [pageCount]="pageCount()" [activePage]="activePage()" (onPaginate)="paginate($event)"></rs-daisy-pagination>
}

View File

@@ -3,7 +3,7 @@ import { EventBusService } from '../../../../../services/event-bus.service';
import { CalendarEventDto } from '../../../models/events-in-range-dto.model';
import { CalendarService } from '../../../../../../api';
import { rxResource } from '@angular/core/rxjs-interop';
import { of } from 'rxjs';
import { delay, of } from 'rxjs';
import { Pagination } from '@rschneider/ng-daisyui';
@Component({
@@ -24,28 +24,32 @@ export class SingleEventBookingList {
// bookings = toSignal(of(['a','b']));
pageSize = input<number>(10);
pageCount = computed(() => {
const bookings = this.bookings.value() ?? [];
let pageCount = Math.floor( bookings.length / this.pageSize());
if ( (bookings.length % this.pageSize()) > 0){
pageCount += 1;
}
pageCount = Math.max(pageCount ,1);
console.info("pageCount", pageCount);
return pageCount;
return this.bookings.value()?.pageCount || 1;
})
bookings = rxResource(
{
params: () => {
params: () => ({
page: this.activePage()
},
}),
stream: ({params}) => {
console.info("loading resource", params);
const allData = ["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t"]
const pageData = allData.slice(this.activePage()-1,this.activePage()+this.pageSize())
let pageCount = Math.floor( allData.length / this.pageSize());
if ( (allData.length % this.pageSize()) > 0){
pageCount += 1;
}
pageCount = Math.max(pageCount ,1);
const pageData = allData.slice( ((this.activePage()-1) * this.pageSize()),this.activePage()*this.pageSize());
console.info("booking page data",pageData);
return of(pageData)
return of({
items: pageData,
pageCount
}).pipe( delay(1000))
},
}

View File

@@ -10,6 +10,7 @@ import {
ParseIntPipe,
UseGuards,
ValidationPipe,
ParseDatePipe,
} from '@nestjs/common';
import { CalendarService } from './calendar.service';
import { GetCalendarDto } from './dto/get-calendar.dto';
@@ -99,4 +100,17 @@ export class CalendarController {
) {
return this.calendarService.cancelBooking(bookingId, cancelBookingDto);
}
@Get('bookings/:eventId/:startTime')
getBookings(
@User() user: types.AppUser,
@Param('eventId', ParseIntPipe) eventId: number,
@Param('startTime', new ParseDatePipe()) startTime: Date,
) {
return this.calendarService.getBookings(
user.user!.userId,
eventId,
startTime,
);
}
}

View File

@@ -590,6 +590,31 @@ export class CalendarService {
return this.bookingRepository.save(booking);
}
async getBookings(
userId: number,
eventId: number,
startTime: Date,
): Promise<Booking[]> {
console.info('getBookings', userId, eventId, startTime);
await Promise.resolve();
// const booking = await this.bookingRepository.findOneBy({ id: bookingId });
// if (!booking) {
// throw new NotFoundException(`Booking with ID ${bookingId} not found.`);
// }
// if (booking.canceledAt) {
// throw new BadRequestException('This booking has already been cancelled.');
// }
//
// // Update the booking with cancellation details
// booking.canceledAt = new Date();
// booking.canceledReason = cancelBookingDto.canceledReason || null;
// booking.canceledByUserId = cancelBookingDto.canceledByUserId;
//
// return this.bookingRepository.save(booking);
return [];
}
private isValidOccurrence(event: Event, occurrenceTime: Date): boolean {
console.info(
'[CalendarService] isValidOccurrence called with event:',