-
+
diff --git a/Uru_NaturalBookingFrontend/Uru_NaturalBookingFrontend/src/app/features/review/review.component.html b/Uru_NaturalBookingFrontend/Uru_NaturalBookingFrontend/src/app/features/review/review.component.html
index 2facfd8..e941375 100644
--- a/Uru_NaturalBookingFrontend/Uru_NaturalBookingFrontend/src/app/features/review/review.component.html
+++ b/Uru_NaturalBookingFrontend/Uru_NaturalBookingFrontend/src/app/features/review/review.component.html
@@ -8,15 +8,7 @@
Busqueda de reserva para review
Ingrese el ID de la reserva para hacer una review
-
- Por favor ingrese un ID de reserva valido.
-
-
- No es un ID de reserva valido
-
-
- El ID de la reserva no puede ser vacio.
-
+
{{getErrorMessage()}}
diff --git a/Uru_NaturalBookingFrontend/Uru_NaturalBookingFrontend/src/app/features/review/review.component.ts b/Uru_NaturalBookingFrontend/Uru_NaturalBookingFrontend/src/app/features/review/review.component.ts
index 7fc38c5..f69eedf 100644
--- a/Uru_NaturalBookingFrontend/Uru_NaturalBookingFrontend/src/app/features/review/review.component.ts
+++ b/Uru_NaturalBookingFrontend/Uru_NaturalBookingFrontend/src/app/features/review/review.component.ts
@@ -6,6 +6,7 @@ import {
Validators,
ValidatorFn,
} from '@angular/forms';
+import { ReserveModelForResponse } from 'src/app/models/ReserveModelForResponse';
import { TouristSpotModelForLodgingResponseModel } from 'src/app/models/TouristSpotModelForLodgingResponseModel';
import { ReserveService } from '../services/reserve.service';
import { TouristSpotService } from '../services/tourist-spot.service';
@@ -20,12 +21,17 @@ export class ReviewComponent implements OnInit {
private reserveService: ReserveService;
+ private reserveExist: boolean;
+
+ public reserveObtenied: ReserveModelForResponse;
+
isShown = false;
constructor(
aServiceOfReserves: ReserveService,
private formBuilder: FormBuilder
) {
+ this.reserveObtenied = null;
this.reserveService = aServiceOfReserves;
this.formGroup = this.formBuilder.group({
reserveSelected: new FormControl('', [
@@ -37,19 +43,43 @@ export class ReviewComponent implements OnInit {
ngOnInit(): void {}
- reserveExist(reserveId: string): boolean {
- return this.reserveService.reserveExist(reserveId);
+ openCommentaryForm(): void {
+ this.reserveService
+ .getReserveById(this.formGroup.controls.reserveSelected.value)
+ .subscribe(
+ (res: ReserveModelForResponse) => {
+ this.markShown(res);
+ },
+ (err) => {
+ if (err.status === 400) {
+ alert(
+ 'Error. No es un formato valido para los identificiadores, el mismo debe ser formato GUID.'
+ );
+ } else {
+ alert(err.error);
+ }
+ }
+ );
}
+ markShown(reserveModel: ReserveModelForResponse): void {
+ this.isShown = reserveModel !== null;
+ }
+
+ getErrorMessage(): string {
+ if (this.formGroup.controls.reserveSelected.hasError('required')) {
+ return 'Error. El identificador es requerido.';
+ }
+ return this.formGroup.controls.reserveSelected.hasError('whitespace')
+ ? 'Error. El indentificador de reserva ingresado no puede ser vacío.'
+ : '';
+ }
+
+
noWhitespaceValidator: ValidatorFn = (control: FormControl) => {
const isWhitespace = (control.value || '').trim().length === 0;
const isValid = !isWhitespace;
return isValid ? null : { whitespace: true };
- };
-
- openCommentaryForm(): void {
- if (this.reserveExist(this.formGroup.controls.reserveSelected.value)) {
- this.isShown = true;
- }
}
+
}
diff --git a/Uru_NaturalBookingFrontend/Uru_NaturalBookingFrontend/src/app/features/services/review.service.ts b/Uru_NaturalBookingFrontend/Uru_NaturalBookingFrontend/src/app/features/services/review.service.ts
index a018549..177d1ea 100644
--- a/Uru_NaturalBookingFrontend/Uru_NaturalBookingFrontend/src/app/features/services/review.service.ts
+++ b/Uru_NaturalBookingFrontend/Uru_NaturalBookingFrontend/src/app/features/services/review.service.ts
@@ -1,17 +1,27 @@
+import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { ReviewModelForResponse } from 'src/app/models/ReviewModelForResponse';
+import { environment } from 'src/environments/environment';
import { ReviewModelForRequest } from '../../models/ReviewModelForRequest';
+import { Observable } from 'rxjs';
@Injectable({
providedIn: 'root'
})
export class ReviewService {
- constructor() { }
+ uri = `${environment.baseUrl}api/reviews`;
- comment(review: ReviewModelForRequest): ReviewModelForResponse {
- return;
- // this is a call into the method of webAPI in controller ReviewController POST
- }
+ constructor(private http: HttpClient) { }
+
+ comment(
+ review: ReviewModelForRequest
+ ): Observable
{
+ return this.http.post(
+ this.uri,
+ review
+ );
+ }
+
}