-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.component.ts
153 lines (114 loc) · 3.79 KB
/
app.component.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
import { Component, OnInit } from '@angular/core';
import {FormControl, FormGroup} from '@angular/forms';
import {HttpClient, HttpResponse,HttpHeaders} from "@angular/common/http";
import { Observable } from 'rxjs';
import { catchError, tap } from 'rxjs/operators';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent implements OnInit{
engWelMes$!: Observable<String>;
freWelMes$!: Observable<String>;
presAn$!: Observable<String>;
constructor(private httpClient:HttpClient){}
private baseURL:string='http://localhost:8080';
private getUrl:string = this.baseURL + '/room/reservation/v1/';
private postUrl:string = this.baseURL + '/room/reservation/v1';
public submitted!:boolean;
roomsearch!:FormGroup;
rooms!:Room[];
request!:ReserveRoomRequest;
currentCheckInVal!:string;
currentCheckOutVal!:string;
ngOnInit(){
this.engWelMes$ = this.httpClient.get(this.baseURL + '/welcome?lang=en-US', {responseType: 'text'} )
this.freWelMes$ = this.httpClient.get(this.baseURL + '/welcome?lang=fr-CA', {responseType: 'text'} )
this.presAn$ = this.httpClient.get(this.baseURL + '/presentation', {responseType: 'text'} )
this.roomsearch= new FormGroup({
checkin: new FormControl(' '),
checkout: new FormControl(' ')
});
// this.rooms=ROOMS;
const roomsearchValueChanges$ = this.roomsearch.valueChanges;
// subscribe to the stream
roomsearchValueChanges$.subscribe(x => {
this.currentCheckInVal = x.checkin;
this.currentCheckOutVal = x.checkout;
});
}
onSubmit({value,valid}:{value:Roomsearch,valid:boolean}){
this.getAll().subscribe(
rooms => {
console.log(Object.values(rooms)[0]);this.rooms=<Room[]>Object.values(rooms)[0];
this.rooms.forEach( room => { room.priceCAD = room.price; room.priceEUR = room.price})
}
);
}
reserveRoom(value:string){
this.request = new ReserveRoomRequest(value, this.currentCheckInVal, this.currentCheckOutVal);
this.createReservation(this.request);
}
createReservation(body:ReserveRoomRequest) {
let bodyString = JSON.stringify(body); // Stringify payload
let headers = new Headers({'Content-Type': 'application/json'}); // ... Set content type to JSON
// let options = new RequestOptions({headers: headers}); // Create a request option
const options = {
headers: new HttpHeaders().append('key', 'value'),
}
this.httpClient.post(this.postUrl, body, options)
.subscribe(res => console.log(res));
}
/*mapRoom(response:HttpResponse<any>): Room[]{
return response.body;
}*/
getAll(): Observable<any> {
return this.httpClient.get(this.baseURL + '/room/reservation/v1?checkin='+ this.currentCheckInVal + '&checkout='+this.currentCheckOutVal, {responseType: 'json'});
}
}
export interface Roomsearch{
checkin:string;
checkout:string;
}
export interface Room{
id:string;
roomNumber:string;
price:string;
priceCAD:string;
priceEUR:string;
links:string;
}
export class ReserveRoomRequest {
roomId:string;
checkin:string;
checkout:string;
constructor(roomId:string,
checkin:string,
checkout:string) {
this.roomId = roomId;
this.checkin = checkin;
this.checkout = checkout;
}
}
/*
var ROOMS: Room[]=[
{
"id": "13932123",
"roomNumber" : "409",
"price" :"20",
"links" : ""
},
{
"id": "139324444",
"roomNumber" : "509",
"price" :"30",
"links" : ""
},
{
"id": "139324888",
"roomNumber" : "609",
"price" :"40",
"links" : ""
}
] */