Skip to content

Commit

Permalink
Adding reservation connected into the webAPI and the confirmation
Browse files Browse the repository at this point in the history
  • Loading branch information
joaquinlamela committed Nov 24, 2020
1 parent 2c6eeb7 commit 9bf5297
Show file tree
Hide file tree
Showing 12 changed files with 133 additions and 105 deletions.
2 changes: 1 addition & 1 deletion Uru_NaturalBooking/Domain/Lodging.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ namespace Model.ForResponse
{
public class ReserveModelForResponse : ModelBaseForResponse<Reserve, ReserveModelForResponse>
{
public Guid Id { get; set; }
public string Name { get; set; }

public string LastName { get; set; }
Expand Down Expand Up @@ -42,6 +43,7 @@ public ReserveModelForResponse() { }

protected override ReserveModelForResponse SetModel(Reserve entity)
{
Id = entity.Id;
Name = entity.Name;
LastName = entity.LastName;
Email = entity.Email;
Expand Down
6 changes: 3 additions & 3 deletions Uru_NaturalBooking/WebApi/Controllers/ReserveController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public ReserveController(IReserveManagement reserveLogic)
reserveManagement = reserveLogic;
}

[HttpGet("{id}", Name = "getReserve")]
[HttpGet("{id}", Name = "reserve")]
public IActionResult Get(Guid id)
{
try
Expand All @@ -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)
{
Expand All @@ -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)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ <h1> Confirmar reserva</h1>
<input formControlName="email" type="email" matInput required>
<mat-error *ngIf="formGroup.controls.email.invalid">{{getErrorMessageEmail()}}</mat-error>
</mat-form-field>
<button class="button" (click)="Reserve()" [disabled]="formGroup.invalid">Confirmar reserva</button>
<button class="button" (click)="createReserve()" [disabled]="formGroup.invalid">Confirmar reserva</button>
</div>
</form>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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({
Expand Down Expand Up @@ -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);
}
);
}
}
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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;
Expand All @@ -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(''),
});
}

Expand All @@ -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),
});
}

Expand All @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<div class="content">
<h4> <strong>!Gracias, {{reserveConfirmation.Name}} {{reserveConfirmation.LastName}}! </strong></h4>
<h4><strong>Tu reserva en {{reserveConfirmation.Lodging.Name}} ha sido {{reserveConfirmation.DescriptionOfState}}
<h4> <strong>!Gracias, {{reserveConfirmation.name}} {{reserveConfirmation.lastName}}! </strong></h4>
<h4><strong>Tu reserva en {{reserveConfirmation.lodging.name}} ha sido {{reserveConfirmation.descriptionOfState}}
</strong></h4>
<p>Te esperamos a partir del <strong>{{reserveConfirmation.CheckIn | date: 'dd/MM/yyyy'}} </strong> </p>
<p>{{reserveConfirmation.DescriptionForGuest}}</p>
<p>Te esperamos a partir del <strong>{{reserveConfirmation.checkIn | date: 'dd/MM/yyyy'}} </strong> </p>
<p>{{reserveConfirmation.descriptionForGuest}}</p>
<h4>No olvide guardar su codigo de reserva:</h4>
<h6><strong>{{reserveConfirmation.Id}}</strong></h6>
<h6><strong>{{reserveConfirmation.id}}</strong></h6>
<img class="confirmationImage" src="../../assets/img/confirmacion.jpg">
<h5>Ante cualquier inconveniente no dude en comunicarse:</h5>
<h6>{{reserveConfirmation.PhoneNumberOfContact}}</h6>
<h6>{{reserveConfirmation.phoneNumberOfContact}}</h6>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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: '[email protected]',
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<ReserveModelForResponse> {
return this.http.get<ReserveModelForResponse>(`${this.uri}/${reserveId}`);
}

updateReserve(
Expand All @@ -50,5 +35,12 @@ export class ReserveService {
// and return the reserve update in ReserveModelForResponse
}

constructor() {}
createReserve(
reserveModelForRequest: ReserveModelForRequest
): Observable<ReserveModelForResponse> {
return this.http.post<ReserveModelForResponse>(
this.uri,
reserveModelForRequest
);
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export class LodgingModelForReserveResponseModel{
public Name: string;
public Address: string;
export class LodgingModelForReserveResponseModel {
public name: string;
public address: string;
}
Original file line number Diff line number Diff line change
@@ -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<ReserveModelForRequest>) {
Object.assign(this, init);
}
public constructor(init?: Partial<ReserveModelForRequest>) {
Object.assign(this, init);
}
}
Loading

0 comments on commit 9bf5297

Please sign in to comment.