1
00:00:00,810 --> 00:00:06,660
So what we want to do this time around is to finish up this screen, so I'm going to search for a reservation

2
00:00:07,380 --> 00:00:15,630
and I will choose the 25th and the twenty sixth as my start and end dates and click on a room.

3
00:00:16,230 --> 00:00:19,560
And I want this to disappear, start date and end date.

4
00:00:19,560 --> 00:00:22,620
And I want it to appear up here as Nona editable text.

5
00:00:22,980 --> 00:00:25,220
I also want to display the wrong name.

6
00:00:25,770 --> 00:00:30,180
And finally I want to be able to make the reservation.

7
00:00:30,200 --> 00:00:34,020
So let's look at how we're displaying this page right now.

8
00:00:34,020 --> 00:00:34,890
Make reservations.

9
00:00:34,890 --> 00:00:35,790
So that's the URL.

10
00:00:36,240 --> 00:00:37,040
Make a reservation.

11
00:00:37,050 --> 00:00:42,630
Let's go back to our code and look at our roots and look at make reservation and see what's happening

12
00:00:42,630 --> 00:00:44,110
in that particular function.

13
00:00:45,240 --> 00:00:50,550
So it looks like what we're doing is creating an empty reservation and then just passing that to the

14
00:00:50,550 --> 00:00:52,120
template along with an empty form.

15
00:00:53,130 --> 00:00:57,680
Well, we already have a reservation and that reservation has most of the information we already need.

16
00:00:57,990 --> 00:01:04,830
So why don't we do something useful with that instead, instead of taking it, creating an empty one,

17
00:01:04,840 --> 00:01:06,570
let's pull the reservation out of the session.

18
00:01:06,570 --> 00:01:08,400
And we did that just a little while ago.

19
00:01:08,410 --> 00:01:12,770
So we did that in this function, which is choose room.

20
00:01:13,420 --> 00:01:19,830
So let's find that here is where we pulled the reservation out of the room, right out of the session,

21
00:01:19,830 --> 00:01:21,260
pulled the reservation out of the session.

22
00:01:21,660 --> 00:01:22,590
So let's copy that.

23
00:01:22,600 --> 00:01:29,790
Go back to our Make Reservation page, get rid of this empty reservation and instead pull one out of

24
00:01:29,820 --> 00:01:35,120
the session and Rez will get stored in reservation.

25
00:01:35,700 --> 00:01:39,090
And here we can't generate a printing error because we technically don't have one.

26
00:01:39,090 --> 00:01:40,440
We just have a true or false for.

27
00:01:40,440 --> 00:01:51,360
OK, so I'll fix that just by saying errors DOD knew and saying I cannot get a reservation from again

28
00:01:52,200 --> 00:01:53,280
from session.

29
00:01:53,310 --> 00:01:57,360
And you're not supposed to start an error message with a capital letter for reasons I've never understood.

30
00:01:57,360 --> 00:01:57,960
But there you go.

31
00:01:58,740 --> 00:01:59,060
All right.

32
00:01:59,070 --> 00:02:00,360
So that fixes that.

33
00:02:00,360 --> 00:02:02,100
Now we have this information.

34
00:02:02,340 --> 00:02:03,480
Is that everything we need?

35
00:02:03,530 --> 00:02:04,200
Let's find out.

36
00:02:04,380 --> 00:02:10,230
Let's go over to our Make Reservation page and see what changes we have to make down here.

37
00:02:10,260 --> 00:02:12,390
I don't need start date and end date anymore.

38
00:02:12,660 --> 00:02:14,820
They have the names of start date and end date.

39
00:02:15,000 --> 00:02:16,140
I don't need those.

40
00:02:16,560 --> 00:02:20,970
Instead, I want to display them up here, but I still need them in the form.

41
00:02:20,970 --> 00:02:22,710
So maybe I'll put them in his hidden fields.

42
00:02:23,250 --> 00:02:33,870
Input type equals hidden naming will start date and value equals and what you might be thinking you

43
00:02:33,870 --> 00:02:34,380
could do.

44
00:02:34,650 --> 00:02:39,420
It's just this resort start date because we have the reservation.

45
00:02:39,420 --> 00:02:40,860
There should be a period, not a comma.

46
00:02:41,370 --> 00:02:42,660
We have the reservation.

47
00:02:42,660 --> 00:02:43,320
We got it right here.

48
00:02:43,320 --> 00:02:47,580
We pulled it out of our date, a variable from the template data and we know it's a reservation.

49
00:02:47,850 --> 00:02:49,650
We can just display reservation start date.

50
00:02:50,130 --> 00:02:51,900
You might think that, but you'd be wrong.

51
00:02:51,900 --> 00:02:56,790
I'm going to duplicate this anyway and just get my end date set up because I'm going to need those in

52
00:02:56,790 --> 00:02:57,120
a minute.

53
00:02:57,480 --> 00:02:58,680
And this would be end date.

54
00:02:59,250 --> 00:03:00,120
But that won't work.

55
00:03:00,120 --> 00:03:05,970
And I won't work because don't forget, if you look at template or look at the models, let's open that

56
00:03:05,970 --> 00:03:06,240
up.

57
00:03:06,840 --> 00:03:09,480
Models don't go and you look at a reservation.

58
00:03:09,480 --> 00:03:12,210
Start date and end date aren't in the right format.

59
00:03:12,240 --> 00:03:16,380
They are stored in whatever go uses for time time.

60
00:03:17,010 --> 00:03:22,680
So they won't display in the format that I need them to display in, which is for your four digit eard

61
00:03:22,680 --> 00:03:25,190
hyphen, two digit month hyphen, two digit day.

62
00:03:26,040 --> 00:03:32,100
So what we need to do is effectively the reverse of what we did some time ago, and that is to take

63
00:03:32,100 --> 00:03:36,600
a time and cast it back into a string in the format we want.

64
00:03:36,600 --> 00:03:38,780
And fortunately, that's really easy.

65
00:03:39,300 --> 00:03:42,570
So at this point, I've pulled my rez out of the session.

66
00:03:42,570 --> 00:03:43,500
That's my reservation.

67
00:03:43,830 --> 00:03:50,160
So I'm going to say SD for start date is assigned the value of rez dot start date.

68
00:03:50,490 --> 00:03:55,530
Then I'll just call the format function, which is built right into the time time and give it the correct

69
00:03:55,530 --> 00:03:55,890
layout.

70
00:03:55,890 --> 00:03:59,010
And if you recall, this is the correct layout.

71
00:04:02,070 --> 00:04:08,730
So that should give me the year, the month and the day, and I can duplicate that and do the same thing

72
00:04:08,730 --> 00:04:12,370
for Endi, which I'll call it change this to end date.

73
00:04:12,720 --> 00:04:14,670
Try that again and date.

74
00:04:15,270 --> 00:04:19,540
Now I have them in strings, but how do I get them from here down to here?

75
00:04:19,920 --> 00:04:22,140
I could stick them in data that would work.

76
00:04:22,440 --> 00:04:27,480
But we already if you look at the template data, we have this string map in the format in our struct,

77
00:04:27,480 --> 00:04:30,250
in our type of template data, we have a string map, so let's use that.

78
00:04:31,140 --> 00:04:31,860
So go back to here.

79
00:04:31,860 --> 00:04:34,020
I'll create a string map, which I'll call string map.

80
00:04:34,890 --> 00:04:43,560
I will assign that the value of make the map string string and then I just assign my start date an end

81
00:04:43,560 --> 00:04:43,850
to it.

82
00:04:43,860 --> 00:04:52,260
So I'll say string map start date is equal to SD and string map.

83
00:04:54,980 --> 00:05:04,190
End date is equal to it, and then I just passed my stirring map as part of my template here because

84
00:05:04,190 --> 00:05:05,360
that type is already there.

85
00:05:05,450 --> 00:05:09,780
We've already added that to the the type template data and we just put our spring map in there.

86
00:05:10,520 --> 00:05:10,820
All right.

87
00:05:10,820 --> 00:05:11,480
So I have that.

88
00:05:11,900 --> 00:05:16,710
Now, let's go back to our reservation page and display some information.

89
00:05:16,820 --> 00:05:23,330
So right now, I can just say in a new paragraph now it comes after reservation details.

90
00:05:23,360 --> 00:05:24,770
I'll use this existing paragraph.

91
00:05:24,770 --> 00:05:28,580
I'll put a line break there and I'll just say a rival.

92
00:05:30,470 --> 00:05:40,080
And then print out from my string map index dot string map, which has a capital M and I called it Start

93
00:05:40,100 --> 00:05:47,210
Underscore Date and I'll copy this whole thing because I'm going to use it in a minute and put a line

94
00:05:47,210 --> 00:05:47,780
break there.

95
00:05:47,960 --> 00:05:56,350
And I replace the start date in here with what I just copy and we'll do the same thing for the end date.

96
00:05:58,630 --> 00:06:01,030
Which I'm going to call departure.

97
00:06:03,370 --> 00:06:11,050
And I'll paste that and change this to end it and paste it in here, actually, I'll just copy the whole

98
00:06:11,050 --> 00:06:13,710
thing that I remember if I copied the curly brackets or not.

99
00:06:14,350 --> 00:06:17,680
And this way I know I'm getting the right thing and pasted in there.

100
00:06:18,130 --> 00:06:22,870
The other thing that we had was a hidden field down here for remedy and remedy is hard coded to one

101
00:06:22,900 --> 00:06:24,990
which isn't very helpful for us.

102
00:06:25,120 --> 00:06:27,390
Fortunately, that's not hard to change either.

103
00:06:28,450 --> 00:06:35,290
So I'm going to change my remedy from the hardcoded value of one to from my reservation variable, which

104
00:06:35,290 --> 00:06:39,130
I got right here, dot room ID.

105
00:06:40,450 --> 00:06:47,380
So if I save that and go back, start my start my applications, I'll clear this, clear the screen,

106
00:06:47,380 --> 00:06:48,430
I'll start my application.

107
00:06:48,430 --> 00:06:49,200
Clear the screen.

108
00:06:49,600 --> 00:06:50,650
Run my application.

109
00:06:53,490 --> 00:06:59,190
And go back to my Web browser and start the whole process over, so click on Make Reservation now choose

110
00:06:59,190 --> 00:07:05,010
and remember the dates I'm choosing 25th and 26th searching.

111
00:07:05,720 --> 00:07:08,740
I'm going to choose major suite, which I know is 82.

112
00:07:08,820 --> 00:07:11,880
I can see that right down in the lower left hand corner of the window.

113
00:07:12,900 --> 00:07:13,610
And there it is.

114
00:07:13,650 --> 00:07:15,900
So it shows me reservation details, arrival.

115
00:07:15,900 --> 00:07:16,590
There's a date.

116
00:07:16,590 --> 00:07:18,300
And I could use whatever format I wanted there.

117
00:07:18,300 --> 00:07:23,850
If I wanted to make it like Thursday, the 25th of November to 2020.

118
00:07:23,880 --> 00:07:29,870
I can format that using my format string in my handler and there's my departure.

119
00:07:29,880 --> 00:07:30,560
That's correct.

120
00:07:30,780 --> 00:07:31,470
I have a room.

121
00:07:31,470 --> 00:07:32,550
It is a hidden field.

122
00:07:32,550 --> 00:07:33,360
Let's make sure.

123
00:07:33,360 --> 00:07:36,590
So let's find room ID.

124
00:07:36,630 --> 00:07:37,860
There it is Editta.

125
00:07:37,860 --> 00:07:38,790
All of that is correct.

126
00:07:39,150 --> 00:07:43,170
The one thing that's missing at this point is the name of the room.

127
00:07:43,410 --> 00:07:49,200
And although technically this will work without it, it would be really helpful if I could display the

128
00:07:49,200 --> 00:07:53,630
room name at the very top, say, between the title and the arrival date.

129
00:07:53,790 --> 00:07:54,650
Can I do that?

130
00:07:54,900 --> 00:07:56,430
Well, let's go look at our model.

131
00:07:58,290 --> 00:08:01,650
So what we have in the actual models, I mean, hi, this

132
00:08:04,830 --> 00:08:10,080
is I have under a reservation, I have the ID, the first name, the last name, the email, the phone,

133
00:08:10,080 --> 00:08:11,130
the start date, the remedy.

134
00:08:11,280 --> 00:08:17,460
I don't have a room name, but I do have this type room which is of type models, dot room right here

135
00:08:17,940 --> 00:08:23,690
and I'm not using it and I know the name of the room at one point during this entire process.

136
00:08:23,970 --> 00:08:31,890
So is it possible that I could populate just the room name field of this room type named room and then

137
00:08:31,890 --> 00:08:33,180
draw it out in my template?

138
00:08:33,180 --> 00:08:33,960
I think it is.

139
00:08:33,990 --> 00:08:35,400
Let's figure out where we could put that.

140
00:08:36,450 --> 00:08:38,550
So let's think about the process.

141
00:08:38,550 --> 00:08:44,580
When I click on the room, I am clicking on Choose Room right here.

142
00:08:44,580 --> 00:08:44,940
Right.

143
00:08:47,040 --> 00:08:47,850
Choose from right here.

144
00:08:48,210 --> 00:08:48,960
Is it in there?

145
00:08:48,960 --> 00:08:50,520
Let's find out in here.

146
00:08:50,520 --> 00:08:57,480
I get the room ID and then I have a reservation which I pull from the court from the session.

147
00:08:58,050 --> 00:09:00,360
So don't I actually don't have it at this point.

148
00:09:00,360 --> 00:09:04,140
At no point in this process do I have the name of the room.

149
00:09:04,320 --> 00:09:05,790
I have it back when I'm searching.

150
00:09:05,790 --> 00:09:11,850
So if we go back here and say search availability, when I post it, I have it right here, but I don't

151
00:09:11,850 --> 00:09:13,530
know which room they're going to choose.

152
00:09:13,710 --> 00:09:19,380
So it seems to me like we're going to have to write another database function to actually go get a room

153
00:09:19,380 --> 00:09:20,300
by ID.

154
00:09:20,750 --> 00:09:23,010
And fortunately, that's really easy.

155
00:09:23,010 --> 00:09:26,700
So let's go over to our where is it here?

156
00:09:26,700 --> 00:09:34,290
It's under internal repository postgrads Digo.

157
00:09:36,160 --> 00:09:36,830
Right here.

158
00:09:37,210 --> 00:09:41,860
So what I'm going to have to do is to write a new function and I'm I have to write a function that gets

159
00:09:41,860 --> 00:09:43,360
a room by ID.

160
00:09:43,360 --> 00:09:48,820
So I will call this func with a receiver of type Postgres DB repo.

161
00:09:49,150 --> 00:09:51,190
I'll say get room.

162
00:09:53,210 --> 00:09:58,040
By I.D., that will be the name of the function, which seems to make sense because that's precisely

163
00:09:58,040 --> 00:10:02,720
what I'm trying to do and it's going to take one parameter, which I'll call ID of type it, and it

164
00:10:02,720 --> 00:10:08,520
will return a model's dot room and it potentially will return an error.

165
00:10:09,710 --> 00:10:14,980
So as I usually do, I'm not going to type out this contact stuff because I almost always get it wrong.

166
00:10:15,350 --> 00:10:19,460
I will copy and paste it and I'll declare a new variable.

167
00:10:19,460 --> 00:10:23,330
VAR are a room of type models dot room.

168
00:10:25,060 --> 00:10:26,090
Then I'll write a query.

169
00:10:26,390 --> 00:10:30,490
My query is going to be equal to Inditex just so I can format it.

170
00:10:30,500 --> 00:10:34,620
However I want select and what's in our room table.

171
00:10:34,640 --> 00:10:35,660
Well let's not guess.

172
00:10:35,690 --> 00:10:36,520
Let's go look.

173
00:10:36,920 --> 00:10:44,960
So I will just pull up my post right here, go to rooms and look at the structure ID room name created

174
00:10:44,960 --> 00:10:45,740
an updated app.

175
00:10:45,980 --> 00:10:46,790
Couldn't be simpler.

176
00:10:46,880 --> 00:10:58,940
Let's go back select ID room name created at updated at from rooms where ID equals dollar sign one.

177
00:10:59,300 --> 00:11:00,080
That's my query.

178
00:11:01,190 --> 00:11:07,040
And since I'm only getting one row I may as well use the query contact query row context.

179
00:11:07,040 --> 00:11:15,020
So row is assigned the value of mpeg db dot query row context, which takes the context which I have

180
00:11:15,020 --> 00:11:21,770
at the very top of this function and my query and my arguments, my one placeholder, which is called

181
00:11:21,770 --> 00:11:29,330
ID, which I receive as a parameter right up here, and then I actually get my error when I try to scan

182
00:11:29,330 --> 00:11:35,330
this row, row, dot scan and I scan it into a variable that I've declared up here but haven't done

183
00:11:35,330 --> 00:11:36,020
anything with yet.

184
00:11:36,410 --> 00:11:39,830
So I'll put room of ampersand.

185
00:11:39,830 --> 00:11:40,940
You got to use a reference to it.

186
00:11:41,150 --> 00:11:48,020
Room ID is my first one room board name is my room name, which is my second one.

187
00:11:48,860 --> 00:11:55,130
And then room dot created art and room updated up there.

188
00:11:55,760 --> 00:11:56,660
So now I have this.

189
00:11:56,660 --> 00:11:57,830
I need to check for my error.

190
00:11:58,640 --> 00:12:02,030
If error is not equal to nil, then what do I do.

191
00:12:02,030 --> 00:12:12,770
I return my variable room and the error, otherwise I return my room and nil because there was no error

192
00:12:13,460 --> 00:12:14,240
and that should do it.

193
00:12:14,420 --> 00:12:16,160
Let's give this a comment.

194
00:12:18,800 --> 00:12:22,130
Gets a room by ID.

195
00:12:25,350 --> 00:12:31,730
And then we need to put this in our repository, so let's get back there, which is under Postgres,

196
00:12:32,400 --> 00:12:41,850
we need to copy this, paste it into our repository so it becomes available, make sure everything compiles.

197
00:12:45,430 --> 00:12:46,510
It does good.

198
00:12:46,570 --> 00:12:49,270
OK, I'll stop the application and now let's go use this.

199
00:12:49,690 --> 00:12:54,040
So back in our handlers, which are right here, when do I want to use this?

200
00:12:54,040 --> 00:12:58,200
I want to use this just before I display the make reservation page.

201
00:12:58,260 --> 00:13:01,690
So let's go back to our roots to get back to the function right here.

202
00:13:02,200 --> 00:13:06,070
At this point, I know the reservation and I know everything I need to know.

203
00:13:06,190 --> 00:13:12,190
All I have to do is to look up the room and store its name in the appropriate location.

204
00:13:12,370 --> 00:13:13,690
In my reservation.

205
00:13:14,680 --> 00:13:21,670
My reservation, so I can do here is actually just say now that I have my reservation, I can say room

206
00:13:21,850 --> 00:13:23,500
or error is a sign.

207
00:13:23,500 --> 00:13:29,440
The value of IMDB, get Rambhai ID and pass it Ransdorf Brumidi.

208
00:13:32,720 --> 00:13:38,840
So now I have if this works as I hope it will, I will have everything about that room stored in this

209
00:13:38,840 --> 00:13:41,330
variable and potentially I have an error, so I've got to check for that.

210
00:13:41,510 --> 00:13:47,780
If error is not equal to nil helper's dot server error, W. error return.

211
00:13:49,190 --> 00:13:55,040
Otherwise I have it and I can just in my reservation I can store the room name so I can say red dot

212
00:13:55,040 --> 00:14:02,060
room dot room name equals room dot room name.

213
00:14:03,830 --> 00:14:08,770
And now I've populated that variable which is of type models.

214
00:14:08,780 --> 00:14:09,710
Dot reservation.

215
00:14:09,830 --> 00:14:13,850
I populated its member room which is a type models dot room.

216
00:14:14,000 --> 00:14:17,420
I've only populated one field but that's all I care about right now.

217
00:14:17,420 --> 00:14:23,180
So I'll just store that in there and we should be good to go because I put this variable in the session

218
00:14:23,180 --> 00:14:23,750
down here.

219
00:14:24,020 --> 00:14:32,330
So if I go back to the make reservation page now at the very top, I can say room and I can just go

220
00:14:33,050 --> 00:14:35,600
rez, which I'm going to have to move something in a second.

221
00:14:35,600 --> 00:14:42,020
But don't worry, I will resort room, dot room name and I can't call this yet.

222
00:14:42,020 --> 00:14:46,010
And actually this helpfully underlines it red showing me because I don't actually declare this variable

223
00:14:46,010 --> 00:14:46,760
until later.

224
00:14:47,120 --> 00:14:49,970
So let's just cut that and move it right up here.

225
00:14:50,570 --> 00:14:51,980
And now that won't be an issue anymore.

226
00:14:53,000 --> 00:14:57,560
And I need to put a carriage return after this, otherwise these will be on the same line.

227
00:14:57,570 --> 00:15:02,450
So I put a line break there and I should be able to stop the application, which has already stopped.

228
00:15:02,450 --> 00:15:05,450
Run it again and try this one more time.

229
00:15:06,260 --> 00:15:13,880
So let's go back here and start over from the homepage and choose make reservation now and search for

230
00:15:13,880 --> 00:15:14,690
availability.

231
00:15:14,810 --> 00:15:23,540
So I'll go the 26th to the 27th this time search, choose the major suite and it shows me the room is

232
00:15:23,540 --> 00:15:24,290
the major suite.

233
00:15:24,410 --> 00:15:24,890
Perfect.

234
00:15:24,900 --> 00:15:26,510
Now let's make sure the last part works.

235
00:15:26,900 --> 00:15:32,270
So I'll put Mary Jones Mary at Jones dot com and some phone number.

236
00:15:34,460 --> 00:15:37,140
And make the reservation and hopefully we haven't broken anything.

237
00:15:38,180 --> 00:15:39,020
Looks good.

238
00:15:39,200 --> 00:15:44,030
We're going to have to change this, of course, the reservation summary page to include the room,

239
00:15:44,240 --> 00:15:47,570
to include the arrival date and include the departure date.

240
00:15:47,780 --> 00:15:49,670
But that should be trivial.

241
00:15:50,180 --> 00:15:50,480
All right.

242
00:15:50,480 --> 00:15:55,790
We'll take care of that last step and a few other minor things that we need to think about, for example,

243
00:15:56,210 --> 00:15:57,890
when I'm searching for a reservation.

244
00:15:58,790 --> 00:16:01,880
Should I be able to choose a date in the past?

245
00:16:02,210 --> 00:16:05,360
Probably not, unless time travel has recently been invented.

246
00:16:05,570 --> 00:16:07,390
That's probably a very bad idea.

247
00:16:07,850 --> 00:16:14,780
So I should modify this calendar such that no date before either today or tomorrow or whatever we decide

248
00:16:14,780 --> 00:16:17,660
the first date should be is even selectable.

249
00:16:18,260 --> 00:16:23,750
And then we're also going to want to probably put server side validation in to make sure that they didn't

250
00:16:23,750 --> 00:16:29,240
turn off JavaScript manually, type in a date in the past, but in the correct format and then submit

251
00:16:29,240 --> 00:16:30,380
the submit the page.

252
00:16:30,380 --> 00:16:33,050
So we're going to want to take care of that as well.

253
00:16:33,060 --> 00:16:34,100
But these are minor things.

254
00:16:34,100 --> 00:16:37,820
They're easy to clean up and we'll take care of that in the next lecture or two.
