Skip to content
Snippets Groups Projects
Commit e3e54da4 authored by migudel's avatar migudel :speech_balloon:
Browse files

listo para entrega

parent e61065cd
No related branches found
No related tags found
1 merge request!26Revert "Funciona register"
...@@ -26,7 +26,7 @@ ...@@ -26,7 +26,7 @@
</div> </div>
<div class="form-group"> <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 <input
type="date" type="date"
id="startDate" id="startDate"
...@@ -36,7 +36,7 @@ ...@@ -36,7 +36,7 @@
</div> </div>
<div class="form-group"> <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 <input
type="date" type="date"
id="endDate" id="endDate"
......
...@@ -81,8 +81,8 @@ export class BookingComponent { ...@@ -81,8 +81,8 @@ export class BookingComponent {
loadBooking() { loadBooking() {
const booking = this.bookingLocal; const booking = this.bookingLocal;
if (!booking) return; if (!booking) return;
const start = new Date(booking.startDate).toISOString().split('T')[0]; const start = new Date(booking.startDate).toISOString();
const end = new Date(booking.endDate).toISOString().split('T')[0]; const end = new Date(booking.endDate).toISOString();
this.bookingForm = this.fb.group({ this.bookingForm = this.fb.group({
roomId: [{ value: booking.roomId, disabled: true }, Validators.required], roomId: [{ value: booking.roomId, disabled: true }, Validators.required],
startDate: [{ value: start, disabled: true }, Validators.required], startDate: [{ value: start, disabled: true }, Validators.required],
......
...@@ -96,7 +96,7 @@ ...@@ -96,7 +96,7 @@
<div class="form-group text-xl flex justify-center gap-20"> <div class="form-group text-xl flex justify-center gap-20">
<mat-form-field> <mat-form-field>
<mat-label class="text-2xl">Enter a date range</mat-label> <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"> <mat-date-range-input [rangePicker]="picker" formGroupName="dateRange">
<input <input
matStartDate matStartDate
...@@ -111,11 +111,6 @@ ...@@ -111,11 +111,6 @@
></mat-datepicker-toggle> ></mat-datepicker-toggle>
<mat-date-range-picker #picker></mat-date-range-picker> <mat-date-range-picker #picker></mat-date-range-picker>
</form> </form>
<!-- (dateInput)="updateStart($event)"
(dateChange)="updateStart($event)" -->
<!-- (dateInput)="updateEnd($event)"
(dateChange)="updateEnd($event)" -->
</mat-form-field> </mat-form-field>
<mat-form-field> <mat-form-field>
<mat-label class="text-2xl">Hotel</mat-label> <mat-label class="text-2xl">Hotel</mat-label>
...@@ -124,6 +119,7 @@ ...@@ -124,6 +119,7 @@
class="text-2xl" class="text-2xl"
(selectionChange)="update()" (selectionChange)="update()"
> >
<mat-option [value]="undefined" class="text-3xl">All</mat-option>
@for (hotel of _hotels; track hotel.id) { @for (hotel of _hotels; track hotel.id) {
<mat-option [value]="hotel" class="text-3xl">{{ <mat-option [value]="hotel" class="text-3xl">{{
hotel.name hotel.name
...@@ -133,7 +129,7 @@ ...@@ -133,7 +129,7 @@
</mat-form-field> </mat-form-field>
<mat-form-field> <mat-form-field>
<mat-label>Filter by Room Type</mat-label> <mat-label>Filter by Room Type</mat-label>
<mat-select [(value)]="roomTypeSelected"> <mat-select [(value)]="roomTypeSelected" (selectionChange)="update()">
@for (type of roomTypes; track type) { @for (type of roomTypes; track type) {
<mat-option [value]="type">{{ type }}</mat-option> <mat-option [value]="type">{{ type }}</mat-option>
} }
......
...@@ -61,7 +61,7 @@ export class HotelListComponent { ...@@ -61,7 +61,7 @@ export class HotelListComponent {
isEditing = false; isEditing = false;
isManaging = false; isManaging = false;
dateRangeForm: FormGroup; dateRangeForm: FormGroup;
hotelSelected?: Hotel; hotelSelected?: Hotel = undefined;
roomTypeSelected: SelectableRoomType = 'All'; roomTypeSelected: SelectableRoomType = 'All';
roomTypes = selectableRoomTypeArray; roomTypes = selectableRoomTypeArray;
rooms: Room[] = []; rooms: Room[] = [];
...@@ -99,13 +99,28 @@ export class HotelListComponent { ...@@ -99,13 +99,28 @@ export class HotelListComponent {
ngOnInit(): void { ngOnInit(): void {
this.getHotels(); this.getHotels();
this.dateRangeForm.get('dateRange')?.valueChanges.subscribe(() => {
this.getHotels();
});
} }
update() { update() {
// TODO completar this.hotels = (
this.hotels = !!this.hotelSelected !!this.hotelSelected
? this._hotels.filter((h) => h.id === this.hotelSelected!.id) ? [...this._hotels].filter((h) => h.id === this.hotelSelected!.id)
: [...this._hotels]; : [...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) { showRequested(room: Room) {
...@@ -126,7 +141,10 @@ export class HotelListComponent { ...@@ -126,7 +141,10 @@ export class HotelListComponent {
} }
getHotels() { getHotels() {
this.hotelClient.getAllHotels().subscribe({ const { start, end } = this.dateRangeForm.value.dateRange;
console.log({ start, end });
this.hotelClient.getAllHotels(start, end).subscribe({
next: (resp) => { next: (resp) => {
if (!!resp && (resp as never[]).length >= 0) { if (!!resp && (resp as never[]).length >= 0) {
this._hotels = resp; this._hotels = resp;
......
...@@ -4,7 +4,6 @@ import { HttpClient } from '@angular/common/http'; ...@@ -4,7 +4,6 @@ import { HttpClient } from '@angular/common/http';
import { Hotel, Room } from '../types'; import { Hotel, Room } from '../types';
import { SessionService } from './session.service'; import { SessionService } from './session.service';
import { catchError, map, switchMap, throwError } from 'rxjs'; import { catchError, map, switchMap, throwError } from 'rxjs';
import { log } from 'console';
@Injectable({ @Injectable({
providedIn: 'root', providedIn: 'root',
...@@ -21,9 +20,12 @@ export class HotelClientService { ...@@ -21,9 +20,12 @@ export class HotelClientService {
return this.http.get<Hotel>(url); return this.http.get<Hotel>(url);
} }
getAllHotels() { getAllHotels(startDate?: Date, endDate?: Date) {
const url = `${this.URI}`; 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) { deleteHotel(id: number) {
......
...@@ -104,7 +104,9 @@ export class SessionService { ...@@ -104,7 +104,9 @@ export class SessionService {
updateData(data: Partial<Session>) { updateData(data: Partial<Session>) {
// const session: Session = { ...this.session$.getValue() } as Session; // const session: Session = { ...this.session$.getValue() } as Session;
const saved = this.getSaved(); 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; const session = { ...saved.session, ...data } as Session;
this.storage.save(this.tokenKey, { this.storage.save(this.tokenKey, {
...saved, ...saved,
......
...@@ -46,7 +46,10 @@ export class UserClientService { ...@@ -46,7 +46,10 @@ export class UserClientService {
updateUser(userId: number, user: Partial<User>) { updateUser(userId: number, user: Partial<User>) {
return this.http.put(`${this.URI}/${userId}`, user).pipe( return this.http.put(`${this.URI}/${userId}`, user).pipe(
tap(() => { tap(() => {
this.sessionService.updateData(user as Partial<Session>); this.sessionService.updateData({
id: userId,
...user,
} as Partial<Session>);
}) })
); );
} }
......
...@@ -41,8 +41,21 @@ public class HotelController { ...@@ -41,8 +41,21 @@ public class HotelController {
// Obtener todos los hoteles // Obtener todos los hoteles
@GetMapping @GetMapping
public List<Hotel> getAllHotels() { public List<Hotel> getAllHotels(
return hotelRepository.findAll(); @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 // Añadir un hotel con sus habitaciones
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment