From 9bf52973a296c9d0e40d136f61801363255d249c Mon Sep 17 00:00:00 2001 From: Joaquin Lamela Date: Tue, 24 Nov 2020 12:48:57 -0300 Subject: [PATCH] Adding reservation connected into the webAPI and the confirmation --- Uru_NaturalBooking/Domain/Lodging.cs | 2 +- .../ForResponse/ReserveModelForResponse.cs | 2 + .../WebApi/Controllers/ReserveController.cs | 6 +-- .../create-reserve.component.html | 2 +- .../create-reserve.component.ts | 38 +++++++++------ .../form-modify-reserve.component.ts | 48 ++++++++++++------- .../reserve-confirmation.component.html | 12 ++--- .../reserve-confirmation.component.ts | 13 ++++- .../app/features/services/reserve.service.ts | 44 +++++++---------- .../LodgingModelForReserveResponseModel.ts | 6 +-- .../src/app/models/ReserveModelForRequest.ts | 27 +++++------ .../src/app/models/ReserveModelForResponse.ts | 38 +++++++-------- 12 files changed, 133 insertions(+), 105 deletions(-) diff --git a/Uru_NaturalBooking/Domain/Lodging.cs b/Uru_NaturalBooking/Domain/Lodging.cs index 005fd34..824e558 100644 --- a/Uru_NaturalBooking/Domain/Lodging.cs +++ b/Uru_NaturalBooking/Domain/Lodging.cs @@ -95,7 +95,7 @@ public double CalculateTotalPrice(int totalDaysToStay, int[] quantityOfGuest) int quantityOfRetired = quantityOfGuest[3]; const double discountForChilds = 0.50; const double discountForBabys = 0.25; - const double discountForRetireds = 0.30; + const double discountForRetireds = 0.70; double quantityOfRetiredToApplyDiscount = Math.Floor(quantityOfRetired / 2.0); double quantityOfRetiredWithOutDiscount = quantityOfRetired - quantityOfRetiredToApplyDiscount; return (PricePerNight * totalDaysToStay) * (quantityOfAdults + (quantityOfChilds * discountForChilds) diff --git a/Uru_NaturalBooking/Model/ForResponse/ReserveModelForResponse.cs b/Uru_NaturalBooking/Model/ForResponse/ReserveModelForResponse.cs index b316d6c..b725dfa 100644 --- a/Uru_NaturalBooking/Model/ForResponse/ReserveModelForResponse.cs +++ b/Uru_NaturalBooking/Model/ForResponse/ReserveModelForResponse.cs @@ -8,6 +8,7 @@ namespace Model.ForResponse { public class ReserveModelForResponse : ModelBaseForResponse { + public Guid Id { get; set; } public string Name { get; set; } public string LastName { get; set; } @@ -42,6 +43,7 @@ public ReserveModelForResponse() { } protected override ReserveModelForResponse SetModel(Reserve entity) { + Id = entity.Id; Name = entity.Name; LastName = entity.LastName; Email = entity.Email; diff --git a/Uru_NaturalBooking/WebApi/Controllers/ReserveController.cs b/Uru_NaturalBooking/WebApi/Controllers/ReserveController.cs index 73e0474..755e573 100644 --- a/Uru_NaturalBooking/WebApi/Controllers/ReserveController.cs +++ b/Uru_NaturalBooking/WebApi/Controllers/ReserveController.cs @@ -24,7 +24,7 @@ public ReserveController(IReserveManagement reserveLogic) reserveManagement = reserveLogic; } - [HttpGet("{id}", Name = "getReserve")] + [HttpGet("{id}", Name = "reserve")] public IActionResult Get(Guid id) { try @@ -48,7 +48,7 @@ public IActionResult Post([FromBody] ReserveModelForRequest aReserveModel) try { Reserve reserve = reserveManagement.Create(ReserveModelForRequest.ToEntity(aReserveModel), aReserveModel.IdOfLodgingToReserve); - return CreatedAtRoute("getReserve", new { id = reserve.Id }, ReserveModelForResponse.ToModel(reserve)); + return CreatedAtRoute("reserve", new { id = reserve.Id }, ReserveModelForResponse.ToModel(reserve)); } catch (DomainBusinessLogicException e) { @@ -71,7 +71,7 @@ public IActionResult Put(Guid idForUpdateReserve, [FromBody] ReserveModelForRequ try { Reserve reserve = reserveManagement.Update(idForUpdateReserve, ReserveModelForRequestUpdate.ToEntity(aReserveModelForUpdate)); - return CreatedAtRoute("getReserve", new { id = reserve.Id }, ReserveModelForResponse.ToModel(reserve)); + return CreatedAtRoute("reserve", new { id = reserve.Id }, ReserveModelForResponse.ToModel(reserve)); } catch (DomainBusinessLogicException e) { diff --git a/Uru_NaturalBookingFrontend/Uru_NaturalBookingFrontend/src/app/features/create-reserve/create-reserve.component.html b/Uru_NaturalBookingFrontend/Uru_NaturalBookingFrontend/src/app/features/create-reserve/create-reserve.component.html index 230ec3b..b37c481 100644 --- a/Uru_NaturalBookingFrontend/Uru_NaturalBookingFrontend/src/app/features/create-reserve/create-reserve.component.html +++ b/Uru_NaturalBookingFrontend/Uru_NaturalBookingFrontend/src/app/features/create-reserve/create-reserve.component.html @@ -40,7 +40,7 @@

Confirmar reserva

{{getErrorMessageEmail()}} - + \ No newline at end of file diff --git a/Uru_NaturalBookingFrontend/Uru_NaturalBookingFrontend/src/app/features/create-reserve/create-reserve.component.ts b/Uru_NaturalBookingFrontend/Uru_NaturalBookingFrontend/src/app/features/create-reserve/create-reserve.component.ts index 370bf2c..dcf2959 100644 --- a/Uru_NaturalBookingFrontend/Uru_NaturalBookingFrontend/src/app/features/create-reserve/create-reserve.component.ts +++ b/Uru_NaturalBookingFrontend/Uru_NaturalBookingFrontend/src/app/features/create-reserve/create-reserve.component.ts @@ -10,6 +10,8 @@ import { LodgingService } from '../services/lodging.service'; import { ReserveModelForRequest } from '../../models/ReserveModelForRequest'; import { ActivatedRoute, Router } from '@angular/router'; import { LodgingModelForResponse } from 'src/app/models/LodgingModelForResponse'; +import { ReserveService } from '../services/reserve.service'; +import { ReserveModelForResponse } from 'src/app/models/ReserveModelForResponse'; @Component({ selector: 'app-create-reserve', @@ -34,7 +36,8 @@ export class CreateReserveComponent implements OnInit { private formBuilder: FormBuilder, aLodgingService: LodgingService, private route: ActivatedRoute, - private router: Router + private router: Router, + private reserveService: ReserveService ) { this.lodgingsService = aLodgingService; this.formGroup = this.formBuilder.group({ @@ -94,19 +97,26 @@ export class CreateReserveComponent implements OnInit { return isValid ? null : { whitespace: true }; }; - public Reserve(): void { + public createReserve(): void { this.reserve = new ReserveModelForRequest(); - this.reserve.Name = this.formGroup.controls.name.value; - this.reserve.LastName = this.formGroup.controls.lastName.value; - this.reserve.Email = this.formGroup.controls.email.value; - this.reserve.CheckIn = this.checkIn; - this.reserve.CheckOut = this.checkOut; - this.reserve.QuantityOfAdult = this.quantityOfGuest[0]; - this.reserve.QuantityOfChild = this.quantityOfGuest[1]; - this.reserve.QuantityOfBaby = this.quantityOfGuest[2]; - this.reserve.QuantityOfRetired = this.quantityOfGuest[3]; - this.reserve.IdOfLodgingToReserve = this.lodgingId; - // call web api post method - this.router.navigate(['reserve-confirmation', '123']); + this.reserve.name = this.formGroup.controls.name.value; + this.reserve.lastName = this.formGroup.controls.lastName.value; + this.reserve.email = this.formGroup.controls.email.value; + this.reserve.checkIn = this.checkIn; + this.reserve.checkOut = this.checkOut; + this.reserve.quantityOfAdult = this.quantityOfGuest[0]; + this.reserve.quantityOfChild = this.quantityOfGuest[1]; + this.reserve.quantityOfBaby = this.quantityOfGuest[2]; + this.reserve.quantityOfRetired = this.quantityOfGuest[3]; + this.reserve.idOfLodgingToReserve = this.lodgingId; + + this.reserveService.createReserve(this.reserve).subscribe( + (res: ReserveModelForResponse) => { + this.router.navigate(['reserve-confirmation', res.id]); + }, + (err) => { + alert(err); + } + ); } } diff --git a/Uru_NaturalBookingFrontend/Uru_NaturalBookingFrontend/src/app/features/form-modify-reserve/form-modify-reserve.component.ts b/Uru_NaturalBookingFrontend/Uru_NaturalBookingFrontend/src/app/features/form-modify-reserve/form-modify-reserve.component.ts index 7d45c01..c129d44 100644 --- a/Uru_NaturalBookingFrontend/Uru_NaturalBookingFrontend/src/app/features/form-modify-reserve/form-modify-reserve.component.ts +++ b/Uru_NaturalBookingFrontend/Uru_NaturalBookingFrontend/src/app/features/form-modify-reserve/form-modify-reserve.component.ts @@ -1,5 +1,11 @@ import { Component, Input, OnInit } from '@angular/core'; -import { FormBuilder, FormControl, FormGroup, ValidatorFn, Validators } from '@angular/forms'; +import { + FormBuilder, + FormControl, + FormGroup, + ValidatorFn, + Validators, +} from '@angular/forms'; import { DescriptionOfState } from 'src/app/models/ReserveState'; import { ReviewModelForRequest } from 'src/app/models/ReviewModelForRequest'; import { ReserveModelForResponse } from '../../models/ReserveModelForResponse'; @@ -9,10 +15,9 @@ import { ReserveModelForRequestUpdate } from '../../models/ReserveModelForReques @Component({ selector: 'app-form-modify-reserve', templateUrl: './form-modify-reserve.component.html', - styleUrls: ['./form-modify-reserve.component.css'] + styleUrls: ['./form-modify-reserve.component.css'], }) export class FormModifyReserveComponent implements OnInit { - @Input() reserveId: string; public formGroup: FormGroup; @@ -25,15 +30,21 @@ export class FormModifyReserveComponent implements OnInit { public stateSelected: number; - constructor(aReserveService: ReserveService, private formBuilder: FormBuilder) { + constructor( + aReserveService: ReserveService, + private formBuilder: FormBuilder + ) { this.reserveService = aReserveService; this.formGroup = this.formBuilder.group({ name: new FormControl(''), lastName: new FormControl(''), email: new FormControl(''), - description: new FormControl('', [Validators.required, this.noWhitespaceValidator]), + description: new FormControl('', [ + Validators.required, + this.noWhitespaceValidator, + ]), reserveState: new FormControl('', [Validators.required]), - nameOfLodging: new FormControl('') + nameOfLodging: new FormControl(''), }); } @@ -46,18 +57,23 @@ export class FormModifyReserveComponent implements OnInit { const isWhitespace = (control.value || '').trim().length === 0; const isValid = !isWhitespace; return isValid ? null : { whitespace: true }; - } + }; public ChargeInfoInFields(): void { - this.reserveSelectedToModify = this.reserveService.getReserveById(this.reserveId); - this.stateSelected = this.reserveSelectedToModify.ReserveState; + //this.reserveSelectedToModify = this.reserveService.getReserveById(this.reserveId); + this.stateSelected = this.reserveSelectedToModify.reserveState; this.formGroup = this.formBuilder.group({ - name: new FormControl(this.reserveSelectedToModify.Name), - lastName: new FormControl(this.reserveSelectedToModify.LastName), - email: new FormControl(this.reserveSelectedToModify.Email), - description: new FormControl(this.reserveSelectedToModify.DescriptionForGuest, [Validators.required, this.noWhitespaceValidator]), - reserveState: new FormControl(this.reserveSelectedToModify.ReserveState, [Validators.required]), - nameOfLodging: new FormControl(this.reserveSelectedToModify.Lodging.Name) + name: new FormControl(this.reserveSelectedToModify.name), + lastName: new FormControl(this.reserveSelectedToModify.lastName), + email: new FormControl(this.reserveSelectedToModify.email), + description: new FormControl( + this.reserveSelectedToModify.descriptionForGuest, + [Validators.required, this.noWhitespaceValidator] + ), + reserveState: new FormControl(this.reserveSelectedToModify.reserveState, [ + Validators.required, + ]), + nameOfLodging: new FormControl(this.reserveSelectedToModify.lodging.name), }); } @@ -70,7 +86,7 @@ export class FormModifyReserveComponent implements OnInit { const reserveToModify: ReserveModelForRequestUpdate = { Id: this.reserveId, Description: this.formGroup.controls.description.value, - StateOfReserve: this.stateSelected + StateOfReserve: this.stateSelected, }; this.reserveService.updateReserve(reserveToModify); } diff --git a/Uru_NaturalBookingFrontend/Uru_NaturalBookingFrontend/src/app/features/reserve-confirmation/reserve-confirmation.component.html b/Uru_NaturalBookingFrontend/Uru_NaturalBookingFrontend/src/app/features/reserve-confirmation/reserve-confirmation.component.html index a036ae8..2d73023 100644 --- a/Uru_NaturalBookingFrontend/Uru_NaturalBookingFrontend/src/app/features/reserve-confirmation/reserve-confirmation.component.html +++ b/Uru_NaturalBookingFrontend/Uru_NaturalBookingFrontend/src/app/features/reserve-confirmation/reserve-confirmation.component.html @@ -1,12 +1,12 @@
-

!Gracias, {{reserveConfirmation.Name}} {{reserveConfirmation.LastName}}!

-

Tu reserva en {{reserveConfirmation.Lodging.Name}} ha sido {{reserveConfirmation.DescriptionOfState}} +

!Gracias, {{reserveConfirmation.name}} {{reserveConfirmation.lastName}}!

+

Tu reserva en {{reserveConfirmation.lodging.name}} ha sido {{reserveConfirmation.descriptionOfState}}

-

Te esperamos a partir del {{reserveConfirmation.CheckIn | date: 'dd/MM/yyyy'}}

-

{{reserveConfirmation.DescriptionForGuest}}

+

Te esperamos a partir del {{reserveConfirmation.checkIn | date: 'dd/MM/yyyy'}}

+

{{reserveConfirmation.descriptionForGuest}}

No olvide guardar su codigo de reserva:

-
{{reserveConfirmation.Id}}
+
{{reserveConfirmation.id}}
Ante cualquier inconveniente no dude en comunicarse:
-
{{reserveConfirmation.PhoneNumberOfContact}}
+
{{reserveConfirmation.phoneNumberOfContact}}

\ No newline at end of file diff --git a/Uru_NaturalBookingFrontend/Uru_NaturalBookingFrontend/src/app/features/reserve-confirmation/reserve-confirmation.component.ts b/Uru_NaturalBookingFrontend/Uru_NaturalBookingFrontend/src/app/features/reserve-confirmation/reserve-confirmation.component.ts index b650325..ef767a6 100644 --- a/Uru_NaturalBookingFrontend/Uru_NaturalBookingFrontend/src/app/features/reserve-confirmation/reserve-confirmation.component.ts +++ b/Uru_NaturalBookingFrontend/Uru_NaturalBookingFrontend/src/app/features/reserve-confirmation/reserve-confirmation.component.ts @@ -24,8 +24,17 @@ export class ReserveConfirmationComponent implements OnInit { ngOnInit(): void { this.reserveId = this.currentRoute.snapshot.params.idReserve; - this.reserveConfirmation = this.reserveService.getReserveById( - this.reserveId + this.getTheReserveConfirmation(this.reserveId); + } + + private getTheReserveConfirmation(reserveId: string): void { + this.reserveService.getReserveById(reserveId).subscribe( + (res: ReserveModelForResponse) => { + this.reserveConfirmation = res; + }, + (err) => { + alert(err.error); + } ); } } diff --git a/Uru_NaturalBookingFrontend/Uru_NaturalBookingFrontend/src/app/features/services/reserve.service.ts b/Uru_NaturalBookingFrontend/Uru_NaturalBookingFrontend/src/app/features/services/reserve.service.ts index 41f5d3e..4ded91c 100644 --- a/Uru_NaturalBookingFrontend/Uru_NaturalBookingFrontend/src/app/features/services/reserve.service.ts +++ b/Uru_NaturalBookingFrontend/Uru_NaturalBookingFrontend/src/app/features/services/reserve.service.ts @@ -4,42 +4,27 @@ import { ReserveState } from 'src/app/models/ReserveState'; import { ReserveModelForResponse } from '../../models/ReserveModelForResponse'; import { DescriptionOfState } from '../../models/ReserveState'; import { ReserveModelForRequestUpdate } from '../../models/ReserveModelForRequestUpdate'; +import { ReserveModelForRequest } from 'src/app/models/ReserveModelForRequest'; +import { Observable } from 'rxjs'; +import { HttpClient } from '@angular/common/http'; +import { environment } from 'src/environments/environment'; @Injectable({ providedIn: 'root', }) export class ReserveService { + uri = `${environment.baseUrl}api/reserves`; + reserveExist(reserveId: string): boolean { return true; // this is a call to the ReserveController in the webAPI to get the reserve by the id, // and in this case if we get a 200 means that reserve exist, in other case not. } - getReserveById(reserveId: string): ReserveModelForResponse { - const reserveModel: ReserveModelForResponse = { - Id: '40a749b8-6c68-4705-af8f-25b967b4c7aa', - Name: 'Joaquin', - PhoneNumberOfContact: 244087645, - QuantityOfAdult: 1, - QuantityOfBaby: 2, - QuantityOfChild: 3, - QuantityOfRetired: 4, - TotalPrice: 1240, - LastName: 'Lamela', - Email: 'joaquin.lamela@gmail.com', - CheckIn: new Date(), - CheckOut: new Date(), - DescriptionForGuest: 'Lo invitamos a pasar un momento asombroso', - ReserveState: ReserveState.Aceptada, - DescriptionOfState: DescriptionOfState.get(ReserveState.Aceptada), - Lodging: { - Name: 'Hotel Enjoy Conrad', - Address: 'Parada 21, Playa Mansa', - }, - }; - return reserveModel; - // this is a call to the ReserveController in the webAPI to get the reserve by the id, - // and in this case if we get a 200 means that reserve exist and i need to charge info + constructor(private http: HttpClient) {} + + getReserveById(reserveId: string): Observable { + return this.http.get(`${this.uri}/${reserveId}`); } updateReserve( @@ -50,5 +35,12 @@ export class ReserveService { // and return the reserve update in ReserveModelForResponse } - constructor() {} + createReserve( + reserveModelForRequest: ReserveModelForRequest + ): Observable { + return this.http.post( + this.uri, + reserveModelForRequest + ); + } } diff --git a/Uru_NaturalBookingFrontend/Uru_NaturalBookingFrontend/src/app/models/LodgingModelForReserveResponseModel.ts b/Uru_NaturalBookingFrontend/Uru_NaturalBookingFrontend/src/app/models/LodgingModelForReserveResponseModel.ts index d00bf0b..12eaa90 100644 --- a/Uru_NaturalBookingFrontend/Uru_NaturalBookingFrontend/src/app/models/LodgingModelForReserveResponseModel.ts +++ b/Uru_NaturalBookingFrontend/Uru_NaturalBookingFrontend/src/app/models/LodgingModelForReserveResponseModel.ts @@ -1,4 +1,4 @@ -export class LodgingModelForReserveResponseModel{ - public Name: string; - public Address: string; +export class LodgingModelForReserveResponseModel { + public name: string; + public address: string; } diff --git a/Uru_NaturalBookingFrontend/Uru_NaturalBookingFrontend/src/app/models/ReserveModelForRequest.ts b/Uru_NaturalBookingFrontend/Uru_NaturalBookingFrontend/src/app/models/ReserveModelForRequest.ts index 25aac00..8a78293 100644 --- a/Uru_NaturalBookingFrontend/Uru_NaturalBookingFrontend/src/app/models/ReserveModelForRequest.ts +++ b/Uru_NaturalBookingFrontend/Uru_NaturalBookingFrontend/src/app/models/ReserveModelForRequest.ts @@ -1,26 +1,25 @@ export class ReserveModelForRequest { + public name: string; - public Name: string; + public lastName: string; - public LastName: string; + public email: string; - public Email: string; + public checkIn: Date; - public CheckIn: Date; + public checkOut: Date; - public CheckOut: Date; + public quantityOfAdult: number; - public QuantityOfAdult: number; + public quantityOfChild: number; - public QuantityOfChild: number; + public quantityOfRetired: number; - public QuantityOfRetired: number; + public quantityOfBaby: number; - public QuantityOfBaby: number; + public idOfLodgingToReserve: string; - public IdOfLodgingToReserve: string; - - public constructor(init?: Partial) { - Object.assign(this, init); - } + public constructor(init?: Partial) { + Object.assign(this, init); + } } diff --git a/Uru_NaturalBookingFrontend/Uru_NaturalBookingFrontend/src/app/models/ReserveModelForResponse.ts b/Uru_NaturalBookingFrontend/Uru_NaturalBookingFrontend/src/app/models/ReserveModelForResponse.ts index e735859..0313df1 100644 --- a/Uru_NaturalBookingFrontend/Uru_NaturalBookingFrontend/src/app/models/ReserveModelForResponse.ts +++ b/Uru_NaturalBookingFrontend/Uru_NaturalBookingFrontend/src/app/models/ReserveModelForResponse.ts @@ -2,24 +2,24 @@ import { LodgingModelForReserveResponseModel } from './LodgingModelForReserveRes import { ReserveState, DescriptionOfState } from './ReserveState'; export class ReserveModelForResponse { - public Id: string; - public Name: string; - public LastName: string; - public Email: string; - public PhoneNumberOfContact: number; - public DescriptionForGuest: string; - public CheckIn: Date; - public CheckOut: Date; - public QuantityOfAdult: number; - public QuantityOfChild: number; - public QuantityOfBaby: number; - public QuantityOfRetired: number; - public ReserveState: ReserveState; - public DescriptionOfState: string; - public Lodging: LodgingModelForReserveResponseModel; - public TotalPrice: number; + public id: string; + public name: string; + public lastName: string; + public email: string; + public phoneNumberOfContact: number; + public descriptionForGuest: string; + public checkIn: Date; + public checkOut: Date; + public quantityOfAdult: number; + public quantityOfChild: number; + public quantityOfBaby: number; + public quantityOfRetired: number; + public reserveState: ReserveState; + public descriptionOfState: string; + public lodging: LodgingModelForReserveResponseModel; + public totalPrice: number; - public constructor(init?: Partial) { - Object.assign(this, init); - } + public constructor(init?: Partial) { + Object.assign(this, init); + } }