Add performance filtering by date range
Introduces a new API method in HttpService to fetch performances by a date filter. ScheduleComponent now generates a date filter for the next 14 days and loads performances using the new filtered endpoint, improving flexibility for bookable days.
This commit is contained in:
@@ -51,6 +51,11 @@ export class HttpService {
|
|||||||
return this.http.get<Vorstellung>(`${this.baseUrl}vorstellung/${id}`);
|
return this.http.get<Vorstellung>(`${this.baseUrl}vorstellung/${id}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* POST /api/vorstellung/filter */
|
||||||
|
getPerformaceByFilter(filter: string[]): Observable<Vorstellung[]> {
|
||||||
|
return this.http.post<Vorstellung[]>(`${this.baseUrl}vorstellung/filter`, filter);
|
||||||
|
}
|
||||||
|
|
||||||
/* POST /api/vorstellung */
|
/* POST /api/vorstellung */
|
||||||
addPerformace(vorstellung: Omit<Vorstellung, 'id'>): Observable<Vorstellung> {
|
addPerformace(vorstellung: Omit<Vorstellung, 'id'>): Observable<Vorstellung> {
|
||||||
return this.http.post<Vorstellung>(`${this.baseUrl}vorstellung`, vorstellung);
|
return this.http.post<Vorstellung>(`${this.baseUrl}vorstellung`, vorstellung);
|
||||||
@@ -67,7 +72,7 @@ export class HttpService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Vorstellung APIs */
|
/* Film APIs */
|
||||||
|
|
||||||
/* GET /api/film */
|
/* GET /api/film */
|
||||||
getMovies(): Observable<Film[]> {
|
getMovies(): Observable<Film[]> {
|
||||||
|
|||||||
@@ -18,15 +18,17 @@ export class ScheduleComponent implements OnInit {
|
|||||||
|
|
||||||
movieSearchResult: string = '';
|
movieSearchResult: string = '';
|
||||||
|
|
||||||
|
private readonly bookableDays: number = 14;
|
||||||
|
|
||||||
private http = inject(HttpService);
|
private http = inject(HttpService);
|
||||||
private loading = inject(LoadingService)
|
private loading = inject(LoadingService)
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
this.generateDates();
|
this.generateDates(this.bookableDays);
|
||||||
}
|
}
|
||||||
|
|
||||||
ngOnInit() {
|
ngOnInit() {
|
||||||
this.loadPerformances();
|
this.loadPerformances(this.bookableDays);
|
||||||
}
|
}
|
||||||
|
|
||||||
hasSearchResults(dateIndex: number): boolean {
|
hasSearchResults(dateIndex: number): boolean {
|
||||||
@@ -37,9 +39,9 @@ export class ScheduleComponent implements OnInit {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
generateDates() {
|
generateDates(bookableDays: number) {
|
||||||
const today = new Date();
|
const today = new Date();
|
||||||
for (let i = 0; i < 14; i++) {
|
for (let i = 0; i < bookableDays; i++) {
|
||||||
const date = new Date(today);
|
const date = new Date(today);
|
||||||
date.setDate(today.getDate() + i);
|
date.setDate(today.getDate() + i);
|
||||||
|
|
||||||
@@ -56,9 +58,10 @@ export class ScheduleComponent implements OnInit {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
loadPerformances() {
|
loadPerformances(bookableDays: number) {
|
||||||
this.loading.show();
|
this.loading.show();
|
||||||
this.http.getPerformaces().pipe(
|
const filter = this.generateDateFilter(bookableDays);
|
||||||
|
this.http.getPerformaceByFilter(filter).pipe(
|
||||||
map(data => Array.isArray(data) ? data : [data]),
|
map(data => Array.isArray(data) ? data : [data]),
|
||||||
tap(performaces => {
|
tap(performaces => {
|
||||||
this.performaces = performaces;
|
this.performaces = performaces;
|
||||||
@@ -67,12 +70,27 @@ export class ScheduleComponent implements OnInit {
|
|||||||
}),
|
}),
|
||||||
catchError(err => {
|
catchError(err => {
|
||||||
this.loading.showError(err);
|
this.loading.showError(err);
|
||||||
console.error('Fehler beim Laden der Vorstellung', err);
|
console.error('Fehler beim Laden der Vorstellungen', err);
|
||||||
return of([]);
|
return of([]);
|
||||||
})
|
})
|
||||||
).subscribe();
|
).subscribe();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private generateDateFilter(bookableDays: number): string[] {
|
||||||
|
const startDate = new Date();
|
||||||
|
const endDate = new Date();
|
||||||
|
endDate.setDate(startDate.getDate() + bookableDays - 1);
|
||||||
|
|
||||||
|
const startStr = startDate.toISOString().split('T')[0] + 'T00:00:00';
|
||||||
|
const endStr = endDate.toISOString().split('T')[0] + 'T23:59:59';
|
||||||
|
|
||||||
|
return [
|
||||||
|
`ge;start;date;${startStr}`,
|
||||||
|
`le;start;date;${endStr}`,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
assignPerformancesToDates() {
|
assignPerformancesToDates() {
|
||||||
|
|
||||||
// Gruppieren nach Datum
|
// Gruppieren nach Datum
|
||||||
|
|||||||
Reference in New Issue
Block a user