diff --git a/angular/RestClient/src/app/core/features/bookings/booking/booking.component.html b/angular/RestClient/src/app/core/features/bookings/booking/booking.component.html index d21112a5b1473871dc8a7df48d3d7125a06c5cb6..fb7485fc16360e63fe916ee75b1f53f320895776 100644 --- a/angular/RestClient/src/app/core/features/bookings/booking/booking.component.html +++ b/angular/RestClient/src/app/core/features/bookings/booking/booking.component.html @@ -26,7 +26,7 @@ </div> <div class="form-group"> - <label for="startDate">Fecha de Inicio (MM/dd/YYYY):</label> + <label for="startDate">Fecha de Inicio (mm/dd/yyyy):</label> <input type="date" id="startDate" @@ -36,7 +36,7 @@ </div> <div class="form-group"> - <label for="endDate">Fecha de Fin (MM/dd/YYYY):</label> + <label for="endDate">Fecha de Fin (mm/dd/yyyy):</label> <input type="date" id="endDate" diff --git a/angular/RestClient/src/app/core/features/bookings/booking/booking.component.ts b/angular/RestClient/src/app/core/features/bookings/booking/booking.component.ts index b7b1dc209637a0ab617eae1ab4f91b0f7a479b2b..6691027e241bff16a2b25fb71e23a1309ec1929e 100644 --- a/angular/RestClient/src/app/core/features/bookings/booking/booking.component.ts +++ b/angular/RestClient/src/app/core/features/bookings/booking/booking.component.ts @@ -81,8 +81,8 @@ export class BookingComponent { loadBooking() { const booking = this.bookingLocal; if (!booking) return; - const start = new Date(booking.startDate).toISOString().split('T')[0]; - const end = new Date(booking.endDate).toISOString().split('T')[0]; + const start = new Date(booking.startDate).toISOString(); + const end = new Date(booking.endDate).toISOString(); this.bookingForm = this.fb.group({ roomId: [{ value: booking.roomId, disabled: true }, Validators.required], startDate: [{ value: start, disabled: true }, Validators.required], diff --git a/angular/RestClient/src/app/core/features/hotel/hotel-list/hotel-list.component.html b/angular/RestClient/src/app/core/features/hotel/hotel-list/hotel-list.component.html index 86b8a3546bcd2d2e9c809872132aa7923dbcb6d0..d0f0b21a8390db0bffa538c150073391b3abcc54 100644 --- a/angular/RestClient/src/app/core/features/hotel/hotel-list/hotel-list.component.html +++ b/angular/RestClient/src/app/core/features/hotel/hotel-list/hotel-list.component.html @@ -96,7 +96,7 @@ <div class="form-group text-xl flex justify-center gap-20"> <mat-form-field> <mat-label class="text-2xl">Enter a date range</mat-label> - <form [formGroup]="dateRangeForm" (change)="update()"> + <form [formGroup]="dateRangeForm"> <mat-date-range-input [rangePicker]="picker" formGroupName="dateRange"> <input matStartDate @@ -111,11 +111,6 @@ ></mat-datepicker-toggle> <mat-date-range-picker #picker></mat-date-range-picker> </form> - <!-- (dateInput)="updateStart($event)" - (dateChange)="updateStart($event)" --> - - <!-- (dateInput)="updateEnd($event)" - (dateChange)="updateEnd($event)" --> </mat-form-field> <mat-form-field> <mat-label class="text-2xl">Hotel</mat-label> @@ -124,6 +119,7 @@ class="text-2xl" (selectionChange)="update()" > + <mat-option [value]="undefined" class="text-3xl">All</mat-option> @for (hotel of _hotels; track hotel.id) { <mat-option [value]="hotel" class="text-3xl">{{ hotel.name @@ -133,7 +129,7 @@ </mat-form-field> <mat-form-field> <mat-label>Filter by Room Type</mat-label> - <mat-select [(value)]="roomTypeSelected"> + <mat-select [(value)]="roomTypeSelected" (selectionChange)="update()"> @for (type of roomTypes; track type) { <mat-option [value]="type">{{ type }}</mat-option> } diff --git a/angular/RestClient/src/app/core/features/hotel/hotel-list/hotel-list.component.ts b/angular/RestClient/src/app/core/features/hotel/hotel-list/hotel-list.component.ts index e684545c1d5b962a028fdc22e0ef2cd842742d86..3ee9b4599e2d393282cd50f660e2e242ece67c7c 100644 --- a/angular/RestClient/src/app/core/features/hotel/hotel-list/hotel-list.component.ts +++ b/angular/RestClient/src/app/core/features/hotel/hotel-list/hotel-list.component.ts @@ -61,7 +61,7 @@ export class HotelListComponent { isEditing = false; isManaging = false; dateRangeForm: FormGroup; - hotelSelected?: Hotel; + hotelSelected?: Hotel = undefined; roomTypeSelected: SelectableRoomType = 'All'; roomTypes = selectableRoomTypeArray; rooms: Room[] = []; @@ -99,13 +99,28 @@ export class HotelListComponent { ngOnInit(): void { this.getHotels(); + this.dateRangeForm.get('dateRange')?.valueChanges.subscribe(() => { + this.getHotels(); + }); } update() { - // TODO completar - this.hotels = !!this.hotelSelected - ? this._hotels.filter((h) => h.id === this.hotelSelected!.id) - : [...this._hotels]; + this.hotels = ( + !!this.hotelSelected + ? [...this._hotels].filter((h) => h.id === this.hotelSelected!.id) + : [...this._hotels] + ) + .map((h) => { + h = { ...h, rooms: [...h.rooms] }; + h.rooms = h.rooms.filter( + (r) => + r.available && + (this.roomTypeSelected === 'All' || + (r.type as SelectableRoomType) === this.roomTypeSelected) + ); + return h; + }) + .filter((h) => h.rooms.length > 0); } showRequested(room: Room) { @@ -126,7 +141,10 @@ export class HotelListComponent { } getHotels() { - this.hotelClient.getAllHotels().subscribe({ + const { start, end } = this.dateRangeForm.value.dateRange; + console.log({ start, end }); + + this.hotelClient.getAllHotels(start, end).subscribe({ next: (resp) => { if (!!resp && (resp as never[]).length >= 0) { this._hotels = resp; diff --git a/angular/RestClient/src/app/shared/hotel-client.service.ts b/angular/RestClient/src/app/shared/hotel-client.service.ts index 6f5a9203df6dcbe5c0cdac2202eddd04ad7141ee..20cd1fd51b5c15effb5d85c1a05bbca99eda3c06 100644 --- a/angular/RestClient/src/app/shared/hotel-client.service.ts +++ b/angular/RestClient/src/app/shared/hotel-client.service.ts @@ -4,7 +4,6 @@ import { HttpClient } from '@angular/common/http'; import { Hotel, Room } from '../types'; import { SessionService } from './session.service'; import { catchError, map, switchMap, throwError } from 'rxjs'; -import { log } from 'console'; @Injectable({ providedIn: 'root', @@ -21,9 +20,12 @@ export class HotelClientService { return this.http.get<Hotel>(url); } - getAllHotels() { + getAllHotels(startDate?: Date, endDate?: Date) { const url = `${this.URI}`; - return this.http.get<Hotel[]>(url); + if (!startDate || !endDate) return this.http.get<Hotel[]>(url); + const start = new Date(startDate).toISOString().split('T')[0]; + const end = new Date(endDate).toISOString().split('T')[0]; + return this.http.get<Hotel[]>(url, { params: { start, end } }); } deleteHotel(id: number) { diff --git a/angular/RestClient/src/app/shared/session.service.ts b/angular/RestClient/src/app/shared/session.service.ts index 796036c5fa4fc2e6b20ab3d9049448be30b8e027..c654e45b787c55dcfe7eae814056c55f6b87549d 100644 --- a/angular/RestClient/src/app/shared/session.service.ts +++ b/angular/RestClient/src/app/shared/session.service.ts @@ -104,7 +104,9 @@ export class SessionService { updateData(data: Partial<Session>) { // const session: Session = { ...this.session$.getValue() } as Session; const saved = this.getSaved(); - if (!saved) return; + console.log({ saved, data }); + + if (!saved || data.id !== saved.session?.id) return; const session = { ...saved.session, ...data } as Session; this.storage.save(this.tokenKey, { ...saved, diff --git a/angular/RestClient/src/app/shared/user-client.service.ts b/angular/RestClient/src/app/shared/user-client.service.ts index 36dd28ae09ce46e8e49af70548588c229b068dd0..63575df4f440973090cde151f50137fb002b9d5d 100644 --- a/angular/RestClient/src/app/shared/user-client.service.ts +++ b/angular/RestClient/src/app/shared/user-client.service.ts @@ -46,7 +46,10 @@ export class UserClientService { updateUser(userId: number, user: Partial<User>) { return this.http.put(`${this.URI}/${userId}`, user).pipe( tap(() => { - this.sessionService.updateData(user as Partial<Session>); + this.sessionService.updateData({ + id: userId, + ...user, + } as Partial<Session>); }) ); } diff --git a/java/roomBooking/src/main/java/com/uva/monolith/services/hotels/controllers/HotelController.java b/java/roomBooking/src/main/java/com/uva/monolith/services/hotels/controllers/HotelController.java index 000345d139ab7c3da4aca18dcef8addc6576c688..b1c172d3aae52a9f482e3baaf9cffe0e56766022 100644 --- a/java/roomBooking/src/main/java/com/uva/monolith/services/hotels/controllers/HotelController.java +++ b/java/roomBooking/src/main/java/com/uva/monolith/services/hotels/controllers/HotelController.java @@ -41,8 +41,21 @@ public class HotelController { // Obtener todos los hoteles @GetMapping - public List<Hotel> getAllHotels() { - return hotelRepository.findAll(); + public List<Hotel> getAllHotels( + @RequestParam(required = false) LocalDate start, + @RequestParam(required = false) LocalDate end) { + List<Hotel> hotels = hotelRepository.findAll(); + if (start != null && end != null) { + // Filtramos para los hoteles que + // tengan habitaciones disponibles para ese rango de fechas + hotels = hotels.stream().map(h -> { + if (h.getRooms().size() == 0) + return h; + h.setRooms(roomRepository.findAvailableRoomsByHotelAndDates(h.getId(), start, end)); + return h; + }).filter(h -> h.getRooms().size() >= 0).toList(); + } + return hotels; } // AƱadir un hotel con sus habitaciones