diff --git a/angular/RestClient/angular.json b/angular/RestClient/angular.json index b9017eb47cbc0d902128a7211d7d8f08c6d1f48a..2fe5dbb241e8371e452ea965dee70c7249575f0c 100644 --- a/angular/RestClient/angular.json +++ b/angular/RestClient/angular.json @@ -44,8 +44,8 @@ "budgets": [ { "type": "initial", - "maximumWarning": "500kB", - "maximumError": "1MB" + "maximumWarning": "1.2MB", + "maximumError": "1.3MB" }, { "type": "anyComponentStyle", @@ -55,6 +55,22 @@ ], "outputHashing": "all" }, + "monolith": { + "fileReplacements": [ + { + "replace": "src/environments/environment.ts", + "with": "src/environments/environment.monolith.ts" + } + ] + }, + "microservices": { + "fileReplacements": [ + { + "replace": "src/environments/environment.ts", + "with": "src/environments/environment.microservices.ts" + } + ] + }, "development": { "optimization": false, "extractLicenses": false, @@ -71,6 +87,12 @@ }, "development": { "buildTarget": "RestClient:build:development" + }, + "monolith": { + "buildTarget": "RestClient:build:monolith" + }, + "microservices": { + "buildTarget": "RestClient:build:microservices" } }, "defaultConfiguration": "development" @@ -102,8 +124,5 @@ } } } - }, - "cli": { - "analytics": false } } diff --git a/angular/RestClient/src/app/core/features/bookings/booking-list/booking-list.component.ts b/angular/RestClient/src/app/core/features/bookings/booking-list/booking-list.component.ts index 06aab259dd9efcd5efaccb4defdacf03a55f3518..5789a064b18d4aa50d9c6d9f163a87fb89bb7afc 100644 --- a/angular/RestClient/src/app/core/features/bookings/booking-list/booking-list.component.ts +++ b/angular/RestClient/src/app/core/features/bookings/booking-list/booking-list.component.ts @@ -8,11 +8,11 @@ import { FormsModule } from '@angular/forms'; import { MatInputModule } from '@angular/material/input'; import { MatSelectModule } from '@angular/material/select'; import { Hotel, Room, RoomType, roomTypeArray } from '../../../../../types'; - import { Router } from '@angular/router'; import { MatCardModule } from '@angular/material/card'; import { MatChipsModule } from '@angular/material/chips'; -import { ClienteApiRestService } from '../../../../shared/cliente-api-rest.service'; +import { LocalStorageService } from '../../../../shared/local-storage.service'; +import { HotelClientService } from '../../../../shared/hotel-client.service'; type SelectableRoomType = 'All' | RoomType; const selectableRoomTypeArray: SelectableRoomType[] = ['All', ...roomTypeArray]; @@ -45,14 +45,18 @@ export class BookingListComponent { rooms: Room[] = []; trateRooms: Room[] = []; - constructor(private router: Router, private client: ClienteApiRestService) {} + constructor( + private router: Router, + private hotelClient: HotelClientService, + private storage: LocalStorageService + ) {} ngOnInit() { this.getHotels(); } getHotels() { - this.client.getAllHotels().subscribe({ + this.hotelClient.getAllHotels().subscribe({ next: (resp) => { if (resp != null) this.hotels = [...resp]; }, @@ -72,7 +76,7 @@ export class BookingListComponent { } search() { - this.client + this.hotelClient .getRoomsAvailableInDateRange( this.hotelSelected!.id, this.start!, @@ -95,14 +99,11 @@ export class BookingListComponent { } bookingRoom(roomId: number) { - localStorage.setItem( - 'booking-data', - JSON.stringify({ - roomId, - startDate: this.start, - endDate: this.end, - }) - ); + this.storage.save('booking-data', { + roomId, + startDate: this.start, + endDate: this.end, + }); this.router.navigate(['/bookings', 'new'], { queryParams: { roomId } }); } } 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 cd63902449b286409ab2ae045a9b273a7033a1f8..9b99737e243b360d543e3ae57ff88d570a39a970 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 @@ -6,10 +6,17 @@ import { Validators, } from '@angular/forms'; -import { BookingService } from '../../../../shared/booking.service'; // Asegúrate de que el servicio exista import { ActivatedRoute, Router } from '@angular/router'; import { Booking, User } from '../../../../../types'; -import { ClienteApiRestService } from '../../../../shared/cliente-api-rest.service'; +import { LocalStorageService } from '../../../../shared/local-storage.service'; +import { BookingClientService } from '../../../../shared/booking-client.service'; +import { UserClientService } from '../../../../shared/user-client.service'; + +type communication = { + roomId: number; + startDate: Date; + endDate: Date; +}; @Component({ standalone: true, @@ -21,15 +28,20 @@ import { ClienteApiRestService } from '../../../../shared/cliente-api-rest.servi export class BookingComponent implements OnInit { users: User[] = []; bookingForm: FormGroup; - bookingLocal: { roomId: number; startDate: Date; endDate: Date }; + bookingLocal: { roomId: number; startDate: Date; endDate: Date } = { + roomId: 0, + endDate: new Date(), + startDate: new Date(), + }; roomId: number = 0; constructor( private router: Router, private route: ActivatedRoute, private fb: FormBuilder, - private bookingService: BookingService, - private client: ClienteApiRestService + private bookingClient: BookingClientService, + private userClient: UserClientService, + private storage: LocalStorageService ) { // Inicialización del formulario con validaciones this.bookingForm = this.fb.group({ @@ -38,21 +50,22 @@ export class BookingComponent implements OnInit { startDate: ['', Validators.required], endDate: ['', Validators.required], }); - const localBookingStr = localStorage.getItem('booking-data'); - if (localBookingStr === null) { + const localBooking = storage.read<communication | null>('booking-data'); + if (localBooking === null) { this.router.navigate(['/booking', 'search']); + return; } - const localBooking = JSON.parse(localBookingStr!); - this.bookingLocal = localBooking; + this.bookingLocal = localBooking!; this.route.queryParams.subscribe((params) => { const roomId = Number(params['roomId']); this.roomId = roomId; - if (localBooking.roomId !== roomId) { + if (this.bookingLocal.roomId !== roomId) { this.router.navigate(['/bookings', 'search']); - this.loadBooking(localBooking); + return; } + this.loadBooking(); }); - this.client.getAllUsers().subscribe({ + this.userClient.getAllUsers().subscribe({ next: (resp) => { this.users = resp; }, @@ -67,10 +80,12 @@ export class BookingComponent implements OnInit { } ngOnInit() { - this.loadBooking(this.bookingLocal); + this.loadBooking(); } - loadBooking(booking: { roomId: number; startDate: Date; endDate: Date }) { + 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]; this.bookingForm = this.fb.group({ @@ -95,11 +110,11 @@ export class BookingComponent implements OnInit { }; // Llama al servicio para crear una nueva reserva - this.bookingService.createBooking(bookingRequest).subscribe({ + this.bookingClient.createBooking(bookingRequest).subscribe({ next: (response) => { console.log('Reserva creada con éxito', response); // Llama al servicio para actualizar el estado del usuario - this.client + this.userClient .alterUserStatus(userId, 'WITH_ACTIVE_BOOKINGS') .subscribe({ next: (response) => { @@ -107,7 +122,7 @@ export class BookingComponent implements OnInit { 'Estado de usuario actualizado con exito', response ); - localStorage.removeItem('booking-data'); + this.storage.remove('booking-data'); this.router.navigate(['/user', userId, 'bookings']); }, error: (error) => { 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 bdd87d3d36ce178cbb994508955b05bec3474803..1bcaf64719ede78b63593bf0c504db6bb263488d 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 @@ -12,7 +12,7 @@ import { MatSlideToggle } from '@angular/material/slide-toggle'; import { MatTable, MatTableModule } from '@angular/material/table'; import { MatButton } from '@angular/material/button'; import { NgbAccordionModule } from '@ng-bootstrap/ng-bootstrap'; -import { ClienteApiRestService } from '../../../../shared/cliente-api-rest.service'; +import { HotelClientService } from '../../../../shared/hotel-client.service'; @Component({ selector: 'app-hotel-list', @@ -38,14 +38,17 @@ export class HotelListComponent { mostrarMensaje!: boolean; mensaje!: string; - constructor(private router: Router, private client: ClienteApiRestService) {} + constructor( + private router: Router, + private hotelClient: HotelClientService + ) {} ngOnInit() { this.getHotels(); } getHotels() { - this.client.getAllHotels().subscribe({ + this.hotelClient.getAllHotels().subscribe({ next: (resp) => { if (!!resp || (resp as never[]).length != 0) this.hotels = [...resp]; }, @@ -59,7 +62,7 @@ export class HotelListComponent { deleteHotel(id: number) { if (!confirm(`Borrar hotel con id ${id}. Continuar?`)) return; - this.client.deleteHotel(id).subscribe({ + this.hotelClient.deleteHotel(id).subscribe({ next: (resp) => { if (resp.status < 400) { this.mostrarMensaje = true; @@ -82,23 +85,25 @@ export class HotelListComponent { roomId: number, availability: boolean ) { - this.client.alterRoomAvailability(hotelId, roomId, availability).subscribe({ - next: (resp) => { - if (resp.status < 400) { - this.mostrarMensaje = true; - this.mensaje = resp.body as string; - this.getHotels(); - } else { - this.mostrarMensaje = true; - this.mensaje = 'Error al cambiar disponibilidad'; - console.error(this.mensaje); - } - }, - error: (error) => { - console.log('Error al cambiar disponibilidad: ' + error.message); - throw error; - }, - }); + this.hotelClient + .alterRoomAvailability(hotelId, roomId, availability) + .subscribe({ + next: (resp) => { + if (resp.status < 400) { + this.mostrarMensaje = true; + this.mensaje = resp.body as string; + this.getHotels(); + } else { + this.mostrarMensaje = true; + this.mensaje = 'Error al cambiar disponibilidad'; + console.error(this.mensaje); + } + }, + error: (error) => { + console.log('Error al cambiar disponibilidad: ' + error.message); + throw error; + }, + }); } goToHotelDetails(hotelId: number): void { diff --git a/angular/RestClient/src/app/core/features/hotel/hotel-register/hotel-register.component.ts b/angular/RestClient/src/app/core/features/hotel/hotel-register/hotel-register.component.ts index fd09a256f2380ae5c144b373f0406228079dcd73..fad7415511aa5a15fc72df3af768f77454f0018f 100644 --- a/angular/RestClient/src/app/core/features/hotel/hotel-register/hotel-register.component.ts +++ b/angular/RestClient/src/app/core/features/hotel/hotel-register/hotel-register.component.ts @@ -13,9 +13,9 @@ import { MatFormFieldModule } from '@angular/material/form-field'; import { MatSelectModule } from '@angular/material/select'; import { MatSlideToggleModule } from '@angular/material/slide-toggle'; import { CommonModule } from '@angular/common'; -import { ClienteApiRestService } from '../../../../shared/cliente-api-rest.service'; import { Address, Hotel, Room } from '../../../../../types'; import { ActivatedRoute, Router } from '@angular/router'; +import { HotelClientService } from '../../../../shared/hotel-client.service'; const emptyRoom: Room = { id: 0, @@ -59,7 +59,7 @@ export class HotelRegisterComponent { private router: Router, private route: ActivatedRoute, private fb: FormBuilder, - private client: ClienteApiRestService + private hotelClient: HotelClientService ) { this.hotelForm = this.setHotelForm(); this.editMode = false; @@ -68,7 +68,7 @@ export class HotelRegisterComponent { const id = Number(params.get('id')); this.editMode = id !== 0; if (this.editMode) { - this.client.getHotel(id).subscribe({ + this.hotelClient.getHotel(id).subscribe({ next: (h) => this.setHotelForm(h), error: (error) => { this.router.navigate(['/hotels/new']); @@ -102,7 +102,7 @@ export class HotelRegisterComponent { onSubmit(): void { if (this.hotelForm.valid) { const hotel = this.hotelForm.value as Hotel; - this.client.addHotel(hotel).subscribe({ + this.hotelClient.addHotel(hotel).subscribe({ next: (resp) => { if (resp.status < 400) { alert('Hotel guardado correctamente'); diff --git a/angular/RestClient/src/app/core/features/user/main-page/main-page.component.ts b/angular/RestClient/src/app/core/features/user/main-page/main-page.component.ts index 55760b59690b884457e25d55f8410a50c81cc0bd..e609b7e568a909e2d6f7efd995ddccb57472cb76 100644 --- a/angular/RestClient/src/app/core/features/user/main-page/main-page.component.ts +++ b/angular/RestClient/src/app/core/features/user/main-page/main-page.component.ts @@ -1,11 +1,11 @@ // main-page.component.ts import { Component, OnInit } from '@angular/core'; -import { ClienteApiRestService } from '../../../../shared/cliente-api-rest.service'; import { User, UserStateFilter } from '../../../../../types'; import { FormsModule } from '@angular/forms'; import { CommonModule } from '@angular/common'; import users from '../../../../../mocks/users.json'; import { RouterModule } from '@angular/router'; +import { UserClientService } from '../../../../shared/user-client.service'; @Component({ standalone: true, imports: [FormsModule, CommonModule, RouterModule], @@ -18,11 +18,11 @@ export class MainPageComponent implements OnInit { filteredUsers: User[] = []; selectedStatus: UserStateFilter = 'All'; - constructor(private ClienteApiRestService: ClienteApiRestService) {} + constructor(private userClient: UserClientService) {} ngOnInit(): void { this.users = users as unknown as User[]; - this.ClienteApiRestService.getAllUsers().subscribe((data: User[]) => { + this.userClient.getAllUsers().subscribe((data: User[]) => { this.users = data; this.filteredUsers = data; // Inicialmente, muestra todos los usuarios }); diff --git a/angular/RestClient/src/app/core/features/user/user-booking-list/user-booking-list.component.ts b/angular/RestClient/src/app/core/features/user/user-booking-list/user-booking-list.component.ts index 5f1b3f1374342c3f9633486e6ce12027c2ebf7c5..10be15d9b999d3d0f2a370236507605df40b4bbd 100644 --- a/angular/RestClient/src/app/core/features/user/user-booking-list/user-booking-list.component.ts +++ b/angular/RestClient/src/app/core/features/user/user-booking-list/user-booking-list.component.ts @@ -1,11 +1,11 @@ import { Component } from '@angular/core'; -import { ClienteApiRestService } from '../../../../shared/cliente-api-rest.service'; + import { Booking, User } from '../../../../../types'; import { ActivatedRoute, RouterModule } from '@angular/router'; -import { MatSelectModule } from '@angular/material/select'; import { CommonModule } from '@angular/common'; import { FormsModule } from '@angular/forms'; -import { BookingService } from '../../../../shared/booking.service'; +import { UserClientService } from '../../../../shared/user-client.service'; +import { BookingClientService } from '../../../../shared/booking-client.service'; type state = 'all' | 'active' | 'inactive'; @@ -24,8 +24,8 @@ export class UserBookingListComponent { user?: User; constructor( - private client: ClienteApiRestService, - private bookingClient: BookingService, + private userClient: UserClientService, + private bookingClient: BookingClientService, private route: ActivatedRoute ) { this.route.paramMap.subscribe({ @@ -34,7 +34,7 @@ export class UserBookingListComponent { this.updateBookings(); }, }); - this.client + this.userClient .getUser(this.userId) .subscribe({ next: (user) => (this.user = user) }); } @@ -44,7 +44,7 @@ export class UserBookingListComponent { } updateBookings() { - this.client.getUserBookings(this.userId).subscribe({ + this.bookingClient.getUserBookings(this.userId).subscribe({ next: (bookings) => { this.search = true; switch (this.selectedState) { @@ -88,7 +88,7 @@ export class UserBookingListComponent { } updateUserStatus() { - this.client.getUserBookings(this.userId).subscribe({ + this.bookingClient.getUserBookings(this.userId).subscribe({ next: (bookings) => { const withActive = bookings.find( (booking) => this.genBookingState(booking) === 'Reserva activa' @@ -97,7 +97,7 @@ export class UserBookingListComponent { (booking) => this.genBookingState(booking) === 'Reserva inactiva' ); if (withActive) { - this.client + this.userClient .alterUserStatus(this.userId, 'WITH_ACTIVE_BOOKINGS') .subscribe({ next: (response) => { @@ -108,7 +108,7 @@ export class UserBookingListComponent { }, }); } else if (withInactive) { - this.client + this.userClient .alterUserStatus(this.userId, 'WITH_INACTIVE_BOOKINGS') .subscribe({ next: (response) => { @@ -123,18 +123,20 @@ export class UserBookingListComponent { }, }); } else { - this.client.alterUserStatus(this.userId, 'NO_BOOKINGS').subscribe({ - next: (response) => { - console.log( - 'Cambio de estado en el usuario a sin reservas correcto' - ); - }, - error: (err) => { - console.error( - 'Error al cambiar de estado al usuario sin reservas' - ); - }, - }); + this.userClient + .alterUserStatus(this.userId, 'NO_BOOKINGS') + .subscribe({ + next: (response) => { + console.log( + 'Cambio de estado en el usuario a sin reservas correcto' + ); + }, + error: (err) => { + console.error( + 'Error al cambiar de estado al usuario sin reservas' + ); + }, + }); } }, }); diff --git a/angular/RestClient/src/app/shared/booking.service.spec.ts b/angular/RestClient/src/app/shared/auth-client.service.spec.ts similarity index 52% rename from angular/RestClient/src/app/shared/booking.service.spec.ts rename to angular/RestClient/src/app/shared/auth-client.service.spec.ts index 3992ef555abf9021f683a3b7fd42344842c4d6ed..718c264fe9fa26ade0a95ea726d68cf899584f1d 100644 --- a/angular/RestClient/src/app/shared/booking.service.spec.ts +++ b/angular/RestClient/src/app/shared/auth-client.service.spec.ts @@ -1,13 +1,13 @@ import { TestBed } from '@angular/core/testing'; -import { BookingService } from './booking.service'; +import { AuthClientService } from './auth-client.service'; -describe('BookingService', () => { - let service: BookingService; +describe('AuthClientService', () => { + let service: AuthClientService; beforeEach(() => { TestBed.configureTestingModule({}); - service = TestBed.inject(BookingService); + service = TestBed.inject(AuthClientService); }); it('should be created', () => { diff --git a/angular/RestClient/src/app/shared/auth-client.service.ts b/angular/RestClient/src/app/shared/auth-client.service.ts new file mode 100644 index 0000000000000000000000000000000000000000..ec3280b68da6db216a68e72c8847e5fee4e6b04d --- /dev/null +++ b/angular/RestClient/src/app/shared/auth-client.service.ts @@ -0,0 +1,11 @@ +import { Injectable } from '@angular/core'; +import { environment } from '../../environments/environment'; + +@Injectable({ + providedIn: 'root', +}) +export class AuthClientService { + private readonly URI = environment.authAPI; + + constructor() {} +} diff --git a/angular/RestClient/src/app/shared/booking-client.service.spec.ts b/angular/RestClient/src/app/shared/booking-client.service.spec.ts new file mode 100644 index 0000000000000000000000000000000000000000..7155f3c6a365fd8f46220cabbf90d2889eeaa05a --- /dev/null +++ b/angular/RestClient/src/app/shared/booking-client.service.spec.ts @@ -0,0 +1,16 @@ +import { TestBed } from '@angular/core/testing'; + +import { BookingClientService } from './booking-client.service'; + +describe('BookingClientService', () => { + let service: BookingClientService; + + beforeEach(() => { + TestBed.configureTestingModule({}); + service = TestBed.inject(BookingClientService); + }); + + it('should be created', () => { + expect(service).toBeTruthy(); + }); +}); diff --git a/angular/RestClient/src/app/shared/booking.service.ts b/angular/RestClient/src/app/shared/booking-client.service.ts similarity index 58% rename from angular/RestClient/src/app/shared/booking.service.ts rename to angular/RestClient/src/app/shared/booking-client.service.ts index 535f4d55ae2c7492a18e0bbf8472c0e78ca99392..7d38299878b9a5500ade1883c47d08585ca01ebb 100644 --- a/angular/RestClient/src/app/shared/booking.service.ts +++ b/angular/RestClient/src/app/shared/booking-client.service.ts @@ -1,22 +1,20 @@ -// booking.service.ts import { Injectable } from '@angular/core'; import { HttpClient, HttpHeaders } from '@angular/common/http'; import { Observable } from 'rxjs'; - +import { environment } from '../../environments/environment'; import { Booking } from '../../types/Booking'; // Ajusta la ruta a tu modelo Booking -import { User, UserState } from '../../types'; @Injectable({ - providedIn: 'root', // Esto hace que el servicio esté disponible en toda la aplicación + providedIn: 'root', }) -export class BookingService { - private apiUrl = 'http://localhost:8080/bookings'; +export class BookingClientService { + private URI = environment.bookingAPI; constructor(private http: HttpClient) {} // Método para crear una nueva reserva createBooking(bookingRequest: Booking): Observable<Booking> { - return this.http.post<Booking>(this.apiUrl, bookingRequest, { + return this.http.post<Booking>(this.URI, bookingRequest, { headers: new HttpHeaders({ 'Content-Type': 'application/json', }), @@ -25,16 +23,21 @@ export class BookingService { // Método para obtener todas las reservas getAllBookings(): Observable<Booking[]> { - return this.http.get<Booking[]>(this.apiUrl); + return this.http.get<Booking[]>(this.URI); } // Método para obtener una reserva por ID getBookingById(id: number): Observable<Booking> { - return this.http.get<Booking>(`${this.apiUrl}/${id}`); + return this.http.get<Booking>(`${this.URI}/${id}`); + } + + getUserBookings(userId: number) { + // TODO revisar tras división en microservicios + return this.http.get<Booking[]>(`${this.URI}/${userId}/bookings`); } // Método para eliminar una reserva deleteBooking(id: number) { - return this.http.delete(`${this.apiUrl}/${id}`); + return this.http.delete(`${this.URI}/${id}`); } } diff --git a/angular/RestClient/src/app/shared/cliente-api-rest.service.spec.ts b/angular/RestClient/src/app/shared/cliente-api-rest.service.spec.ts deleted file mode 100644 index 737c9449305eb7a05fdbb88e75ef1492b05990b3..0000000000000000000000000000000000000000 --- a/angular/RestClient/src/app/shared/cliente-api-rest.service.spec.ts +++ /dev/null @@ -1,16 +0,0 @@ -import { TestBed } from '@angular/core/testing'; - -import { ClienteApiRestService } from './cliente-api-rest.service'; - -describe('ClienteApiRestService', () => { - let service: ClienteApiRestService; - - beforeEach(() => { - TestBed.configureTestingModule({}); - service = TestBed.inject(ClienteApiRestService); - }); - - it('should be created', () => { - expect(service).toBeTruthy(); - }); -}); diff --git a/angular/RestClient/src/app/shared/cliente-api-rest.service.ts b/angular/RestClient/src/app/shared/cliente-api-rest.service.ts deleted file mode 100644 index cb4326ef52f9ed54bc172aa9fad9406872423815..0000000000000000000000000000000000000000 --- a/angular/RestClient/src/app/shared/cliente-api-rest.service.ts +++ /dev/null @@ -1,93 +0,0 @@ -import { HttpClient } from '@angular/common/http'; -import { Injectable } from '@angular/core'; -import { Hotel, Booking, Room, UserState } from '../../types'; -import { User } from '../../types'; - -@Injectable({ - providedIn: 'root', -}) -export class ClienteApiRestService { - private static readonly BASE_URI = 'http://localhost:8080'; - private static readonly HOTEL_URI = `${ClienteApiRestService.BASE_URI}/hotels`; - private static readonly USER_URI = `${ClienteApiRestService.BASE_URI}/users`; - constructor(private http: HttpClient) {} - - getHotel(id: number) { - const url = `${ClienteApiRestService.HOTEL_URI}/${id}`; - return this.http.get<Hotel>(url); - } - - getAllHotels() { - const url = `${ClienteApiRestService.HOTEL_URI}`; - return this.http.get<Hotel[]>(url); - } - - deleteHotel(id: number) { - const url = `${ClienteApiRestService.HOTEL_URI}/${id}`; - return this.http.delete(url, { observe: 'response', responseType: 'text' }); - } - - addHotel(hotel: Hotel) { - const url = `${ClienteApiRestService.HOTEL_URI}`; - return this.http.post(url, hotel, { - observe: 'response', - responseType: 'text', - }); - } - - alterRoomAvailability( - hotelId: number, - roomId: number, - availability: boolean - ) { - const url = `${ClienteApiRestService.HOTEL_URI}/${hotelId}/rooms/${roomId}`; - return this.http.patch( - url, - { available: availability }, - { - observe: 'response', - responseType: 'text', - } - ); - } - - createBooking(bookingRequest: Booking) { - return this.http.post('http://localhost:8080/bookings', bookingRequest); - } - - getRoomsAvailableInDateRange(hotelId: number, start: Date, end: Date) { - const startStr = start.toISOString().split('T')[0]; - const endStr = end.toISOString().split('T')[0]; - const url = `${ClienteApiRestService.HOTEL_URI}/${hotelId}/rooms?start=${startStr}&end=${endStr}`; - return this.http.get<Room[]>(url); - } - - getUser(userId: number) { - return this.http.get<User>(`http://localhost:8080/users/${userId}`); - } - - getAllUsers() { - return this.http.get<User[]>('http://localhost:8080/users', { - observe: 'body', - }); - } - - getUserBookings(userId: number) { - return this.http.get<Booking[]>( - `${ClienteApiRestService.BASE_URI}/users/${userId}/bookings` - ); - } - - alterUserStatus(userId: number, status: UserState) { - return this.http.patch( - `${ClienteApiRestService.BASE_URI}/users/${userId}`, - { - status, - }, - { - observe: 'response', - responseType: 'text', - } - ); - } -} diff --git a/angular/RestClient/src/app/shared/data.service.ts b/angular/RestClient/src/app/shared/data.service.ts deleted file mode 100644 index f22afaeb6662ab48290b344d645945fc9a1c77b0..0000000000000000000000000000000000000000 --- a/angular/RestClient/src/app/shared/data.service.ts +++ /dev/null @@ -1,23 +0,0 @@ -import { Injectable } from '@angular/core'; -import { BehaviorSubject } from 'rxjs'; - -@Injectable({ - providedIn: 'root', -}) -export class DataService { - private message = new BehaviorSubject('hotel list'); - currentMessage = this.message.asObservable(); - - private showMessage = new BehaviorSubject<boolean>(false); - showCurrentMessage = this.showMessage.asObservable(); - - constructor() {} - - setMessage(message: string) { - this.message.next(message); - } - - setShowCurrentMessage(valor: boolean) { - this.showMessage.next(valor); - } -} diff --git a/angular/RestClient/src/app/shared/hotel-client.service.spec.ts b/angular/RestClient/src/app/shared/hotel-client.service.spec.ts new file mode 100644 index 0000000000000000000000000000000000000000..5d32879cfc481ef393ffba104889798d7d982863 --- /dev/null +++ b/angular/RestClient/src/app/shared/hotel-client.service.spec.ts @@ -0,0 +1,16 @@ +import { TestBed } from '@angular/core/testing'; + +import { HotelClientService } from './hotel-client.service'; + +describe('HotelClientService', () => { + let service: HotelClientService; + + beforeEach(() => { + TestBed.configureTestingModule({}); + service = TestBed.inject(HotelClientService); + }); + + it('should be created', () => { + expect(service).toBeTruthy(); + }); +}); diff --git a/angular/RestClient/src/app/shared/hotel-client.service.ts b/angular/RestClient/src/app/shared/hotel-client.service.ts new file mode 100644 index 0000000000000000000000000000000000000000..f00b3e6d5259866c895bffa7856e8e838ae85deb --- /dev/null +++ b/angular/RestClient/src/app/shared/hotel-client.service.ts @@ -0,0 +1,58 @@ +import { Injectable } from '@angular/core'; +import { environment } from '../../environments/environment'; +import { HttpClient } from '@angular/common/http'; +import { Hotel, Room } from '../../types'; + +@Injectable({ + providedIn: 'root', +}) +export class HotelClientService { + private readonly URI = environment.hotelAPI; + constructor(private http: HttpClient) {} + + getHotel(id: number) { + const url = `${this.URI}/${id}`; + return this.http.get<Hotel>(url); + } + + getAllHotels() { + const url = `${this.URI}`; + return this.http.get<Hotel[]>(url); + } + + deleteHotel(id: number) { + const url = `${this.URI}/${id}`; + return this.http.delete(url, { observe: 'response', responseType: 'text' }); + } + + addHotel(hotel: Hotel) { + const url = `${this.URI}`; + return this.http.post(url, hotel, { + observe: 'response', + responseType: 'text', + }); + } + + alterRoomAvailability( + hotelId: number, + roomId: number, + availability: boolean + ) { + const url = `${this.URI}/${hotelId}/rooms/${roomId}`; + return this.http.patch( + url, + { available: availability }, + { + observe: 'response', + responseType: 'text', + } + ); + } + + getRoomsAvailableInDateRange(hotelId: number, start: Date, end: Date) { + const startStr = start.toISOString().split('T')[0]; + const endStr = end.toISOString().split('T')[0]; + const url = `${this.URI}/${hotelId}/rooms?start=${startStr}&end=${endStr}`; + return this.http.get<Room[]>(url); + } +} diff --git a/angular/RestClient/src/app/shared/local-storage.service.spec.ts b/angular/RestClient/src/app/shared/local-storage.service.spec.ts new file mode 100644 index 0000000000000000000000000000000000000000..ba1dbd4362ebcfddcd262fc30de07f4beeb466e3 --- /dev/null +++ b/angular/RestClient/src/app/shared/local-storage.service.spec.ts @@ -0,0 +1,16 @@ +import { TestBed } from '@angular/core/testing'; + +import { LocalStorageService } from './local-storage.service'; + +describe('LocalStorageService', () => { + let service: LocalStorageService; + + beforeEach(() => { + TestBed.configureTestingModule({}); + service = TestBed.inject(LocalStorageService); + }); + + it('should be created', () => { + expect(service).toBeTruthy(); + }); +}); diff --git a/angular/RestClient/src/app/shared/local-storage.service.ts b/angular/RestClient/src/app/shared/local-storage.service.ts new file mode 100644 index 0000000000000000000000000000000000000000..e1526f8aaa1b56903668de93697f4a2b072d97ab --- /dev/null +++ b/angular/RestClient/src/app/shared/local-storage.service.ts @@ -0,0 +1,42 @@ +import { isPlatformBrowser } from '@angular/common'; +import { Inject, Injectable, PLATFORM_ID } from '@angular/core'; + +@Injectable({ + providedIn: 'root', +}) +export class LocalStorageService { + // isBrowser: boolean; + + // constructor(@Inject(PLATFORM_ID) private platformId: Object) { + // this.isBrowser = isPlatformBrowser(this.platformId); + // } + + save(key: string, value: any) { + // if (!this.isBrowser) return; + localStorage.setItem(key, JSON.stringify(value)); + } + + read<T>(key: string) { + // if (!this.isBrowser) return null; + + const json = localStorage.getItem(key); + const ret = json ? (JSON.parse(json) as T) : null; + return ret; + } + + consume<T>(key: string) { + // if (!this.isBrowser) return null; + + const value = this.read<T>(key); + if (value !== null) { + this.remove(key); + } + return value; + } + + remove(key: string) { + // if (!this.isBrowser) return; + + localStorage.removeItem(key); + } +} diff --git a/angular/RestClient/src/app/shared/data.service.spec.ts b/angular/RestClient/src/app/shared/user-client.service.spec.ts similarity index 52% rename from angular/RestClient/src/app/shared/data.service.spec.ts rename to angular/RestClient/src/app/shared/user-client.service.spec.ts index 38e8d9ec63f1f637f51a18393f66c56d564e49a9..3af6ef2803edf936358c39133305278bb689dd4c 100644 --- a/angular/RestClient/src/app/shared/data.service.spec.ts +++ b/angular/RestClient/src/app/shared/user-client.service.spec.ts @@ -1,13 +1,13 @@ import { TestBed } from '@angular/core/testing'; -import { DataService } from './data.service'; +import { UserClientService } from './user-client.service'; -describe('DataService', () => { - let service: DataService; +describe('UserClientService', () => { + let service: UserClientService; beforeEach(() => { TestBed.configureTestingModule({}); - service = TestBed.inject(DataService); + service = TestBed.inject(UserClientService); }); it('should be created', () => { diff --git a/angular/RestClient/src/app/shared/user-client.service.ts b/angular/RestClient/src/app/shared/user-client.service.ts new file mode 100644 index 0000000000000000000000000000000000000000..ea51f7e5060cf349c86159e981748a028806ef80 --- /dev/null +++ b/angular/RestClient/src/app/shared/user-client.service.ts @@ -0,0 +1,35 @@ +import { HttpClient } from '@angular/common/http'; +import { Injectable } from '@angular/core'; +import { environment } from '../../environments/environment'; +import { User, UserState } from '../../types'; + +@Injectable({ + providedIn: 'root', +}) +export class UserClientService { + private readonly URI = environment.userAPI; + constructor(private http: HttpClient) {} + + getUser(userId: number) { + return this.http.get<User>(`${this.URI}/${userId}`); + } + + getAllUsers() { + return this.http.get<User[]>(this.URI, { + observe: 'body', + }); + } + + alterUserStatus(userId: number, status: UserState) { + return this.http.patch( + `${this.URI}/${userId}`, + { + status, + }, + { + observe: 'response', + responseType: 'text', + } + ); + } +} diff --git a/angular/RestClient/src/environments/environment.monolith.ts b/angular/RestClient/src/environments/environment.monolith.ts new file mode 100644 index 0000000000000000000000000000000000000000..676025533ad47d166dedf355b0a08f5e8a96e904 --- /dev/null +++ b/angular/RestClient/src/environments/environment.monolith.ts @@ -0,0 +1,10 @@ +// Simple -> Un servicio fachada / monolito +const hostname = 'http://localhost:8080'; + +export const environment = { + production: false, + authAPI: `${hostname}/auth`, + userAPI: `${hostname}/users`, + hotelAPI: `${hostname}/hotels`, + bookingAPI: `${hostname}/bookings`, +}; diff --git a/angular/RestClient/src/environments/environment.prod.ts b/angular/RestClient/src/environments/environment.prod.ts new file mode 100644 index 0000000000000000000000000000000000000000..445f0d3b770f01162006dbe8262e44338b9161e5 --- /dev/null +++ b/angular/RestClient/src/environments/environment.prod.ts @@ -0,0 +1,8 @@ +// Disgregado en microservicios +export const environment = { + production: true, + authAPI: 'http://auth-api:8080', + userAPI: 'http://user-api:8080', + hotelAPI: 'http://hotels-api:8080', + bookingAPI: 'http://bookings-api:8080', +}; diff --git a/angular/RestClient/src/environments/environment.ts b/angular/RestClient/src/environments/environment.ts new file mode 100644 index 0000000000000000000000000000000000000000..b5fe467280faf9259227fb281e401cff79c5aa87 --- /dev/null +++ b/angular/RestClient/src/environments/environment.ts @@ -0,0 +1,8 @@ +// Disgregado en microservicios +export const environment = { + production: false, + authAPI: 'http://localhost:8101', + userAPI: 'http://localhost:8111', + hotelAPI: 'http://localhost:8121', + bookingAPI: 'http://localhost:8131', +}; diff --git a/java/roomBooking/src/main/java/com/uva/roomBooking/Controllers/BookingController.java b/java/roomBooking/src/main/java/com/uva/roomBooking/Controllers/BookingController.java index c52866c2ca28e056ad9551b42e007c0f2f487a80..5baa50358b36dfffd3184fd0e7e46a9177b2ef55 100644 --- a/java/roomBooking/src/main/java/com/uva/roomBooking/Controllers/BookingController.java +++ b/java/roomBooking/src/main/java/com/uva/roomBooking/Controllers/BookingController.java @@ -19,7 +19,7 @@ import java.util.List; @RestController @RequestMapping("/bookings") -@CrossOrigin(origins = "http://localhost:4200") +@CrossOrigin(origins = "*") public class BookingController { private final BookingRepository bookingRepository;