1
00:00:01,940 --> 00:00:10,290
OK, so this time around, we want to get this form when we submit it with all proper data.

2
00:00:10,310 --> 00:00:13,390
So anything that will pass validation is suitable for right now.

3
00:00:13,970 --> 00:00:15,840
We don't want it to display this blank screen.

4
00:00:15,860 --> 00:00:18,200
We want it to display a reservation summary.

5
00:00:18,710 --> 00:00:22,400
So that shows the user what they're registered for.

6
00:00:22,410 --> 00:00:24,200
We're giving them a confirmation, basically.

7
00:00:24,230 --> 00:00:26,800
And again, we don't have enough information on the form right now.

8
00:00:26,810 --> 00:00:28,040
We don't know what room they're in.

9
00:00:28,040 --> 00:00:31,960
We're not bothering to display the dates of the reservation, but we'll get to that right now.

10
00:00:31,970 --> 00:00:35,200
We're just going to get things up and running as a kind of wireframe.

11
00:00:36,140 --> 00:00:39,320
So the first thing I'm going to need, obviously, is somewhere near my templates.

12
00:00:39,320 --> 00:00:44,870
I'm going to create a new template and I will call that new file, not a go file.

13
00:00:45,560 --> 00:00:51,020
I will call it reservation summary page, Dot Key and Peele.

14
00:00:51,500 --> 00:00:57,650
And this is just going to be a summary page so I can go to the about page, for example, and just copy

15
00:00:57,650 --> 00:01:00,770
everything in there to give it a kind of starter.

16
00:01:01,580 --> 00:01:05,560
So we're going to have information display and we want a title.

17
00:01:05,570 --> 00:01:06,860
So let's give this title.

18
00:01:07,040 --> 00:01:12,320
We'll push the title down a little bit by giving it a class of MTV five.

19
00:01:12,350 --> 00:01:15,860
That's one of the bootstrap building classes that pushes it down from the top of the page.

20
00:01:15,860 --> 00:01:16,940
So it's not quite so crowded.

21
00:01:16,940 --> 00:01:22,000
And we'll just call the title reservation summary.

22
00:01:23,570 --> 00:01:30,470
All right, now, underneath that, I'm going to put an H.R., just a nice line, and then I'm going

23
00:01:30,470 --> 00:01:32,060
to create a table, which you haven't done yet.

24
00:01:32,090 --> 00:01:33,980
You may have done it, but some of you may not have done it.

25
00:01:33,980 --> 00:01:38,900
So let's build a table and a table is built just using standard HTML like this.

26
00:01:38,900 --> 00:01:39,530
It's a table.

27
00:01:39,530 --> 00:01:43,760
And I'm going to use one of the classes are some of the classes built into Bootstrap to make it a little

28
00:01:43,760 --> 00:01:44,180
prettier.

29
00:01:44,810 --> 00:01:49,520
So bootstraps default class for table is not surprisingly called table.

30
00:01:49,530 --> 00:01:55,670
So that'll apply default bootstrap styling to it and then I'll make it striped just so it's easier to

31
00:01:55,670 --> 00:01:57,080
read tables straight.

32
00:01:58,310 --> 00:02:02,210
OK, so there is a table tag now.

33
00:02:02,210 --> 00:02:04,280
A table typically has a head.

34
00:02:05,210 --> 00:02:07,430
Those would be column headings, the top of the table.

35
00:02:07,430 --> 00:02:09,830
But I'm going to leave an empty one in there because I don't really need it.

36
00:02:10,360 --> 00:02:11,960
I'll put it in just because it's nice to have it.

37
00:02:13,400 --> 00:02:16,070
And then it has a body which is called Tibaldi.

38
00:02:16,670 --> 00:02:20,680
And inside of that you have rows and columns and we're going to have a row.

39
00:02:20,690 --> 00:02:21,830
So we'll make one row.

40
00:02:22,220 --> 00:02:29,720
And inside of that will make a column inside of that row TD and we'll give it a label name.

41
00:02:30,350 --> 00:02:34,820
And we don't actually know how to get the name here yet, but we're going to put it in a column right

42
00:02:34,820 --> 00:02:35,170
beside.

43
00:02:36,050 --> 00:02:39,860
And I'm going to copy this and paste it for the other three pieces of data.

44
00:02:40,640 --> 00:02:43,980
So we're going to have their arrival, which we don't know yet.

45
00:02:44,000 --> 00:02:46,020
We're going to have their departure, which we don't know yet.

46
00:02:46,130 --> 00:02:49,100
We're going to have their email, which we do know and we're going to other phone.

47
00:02:49,760 --> 00:02:53,360
So we'll put arrival and departure.

48
00:02:56,280 --> 00:03:05,890
And email and phone, OK, so there is enough information for us right now.

49
00:03:05,910 --> 00:03:10,830
We'll be able to display some of the content that we have from our posted form.

50
00:03:10,830 --> 00:03:14,160
And we're going to populate this with that information, with the bits we know right now.

51
00:03:14,170 --> 00:03:16,790
We don't know arrival and departure, but we're going to get there eventually.

52
00:03:16,800 --> 00:03:18,000
So I'll put them in as placeholders.

53
00:03:18,060 --> 00:03:18,390
Great.

54
00:03:18,400 --> 00:03:21,030
So I've created this this template.

55
00:03:21,060 --> 00:03:23,510
Now I need a handler to display that template.

56
00:03:23,520 --> 00:03:28,080
So let's go to our handlers and let's just create one cold.

57
00:03:28,080 --> 00:03:28,950
We'll put it right at the bottom.

58
00:03:29,600 --> 00:03:31,640
I'll call it funk.

59
00:03:32,100 --> 00:03:39,450
And again, it's going to be linked to a receiver for a repository and I'll call it, oh, reservations,

60
00:03:39,450 --> 00:03:39,750
memory.

61
00:03:42,300 --> 00:03:50,160
And because it's a handler has to take a writer, HTP response writer and it has to take a pointer to

62
00:03:50,160 --> 00:03:56,500
an umpire, a pointer to an update request there.

63
00:03:56,550 --> 00:03:57,720
We have a handler now.

64
00:03:57,720 --> 00:04:03,920
So let's go to our roots file and create a route for that that's under command web routes.

65
00:04:05,790 --> 00:04:09,040
So we'll put this near the reservation stuff right here.

66
00:04:09,240 --> 00:04:18,150
Is good a place as any and it will be a get request reservation summary and it will point to our handlers

67
00:04:18,930 --> 00:04:25,160
in our repository repo the reservation summary there.

68
00:04:25,680 --> 00:04:26,850
So now we have a route to it.

69
00:04:26,950 --> 00:04:27,690
That's great.

70
00:04:28,410 --> 00:04:34,350
So let's go back to our handler for a minute and think about how we're going to get from back to roots,

71
00:04:34,710 --> 00:04:40,760
how we're going to get from this post of search availability to this get a reservation summary.

72
00:04:40,770 --> 00:04:48,000
So in other words, they're posting the form here, which is post availability, not post availability.

73
00:04:48,510 --> 00:04:51,030
RM1 forms route's.

74
00:04:52,410 --> 00:04:55,020
From here, so reservation summary, it doesn't belong here.

75
00:04:55,140 --> 00:04:57,510
Let's get it out of there and put it down here.

76
00:04:57,540 --> 00:04:58,640
We're making a reservation.

77
00:04:58,950 --> 00:05:01,250
So in other words, let's try this again.

78
00:05:01,290 --> 00:05:04,860
We're going from post reservation and we want to get to reservation summary.

79
00:05:04,870 --> 00:05:07,260
So let's go to post reservation and see what we're doing.

80
00:05:08,400 --> 00:05:09,930
So we're parsing the form.

81
00:05:09,930 --> 00:05:11,780
We're building our reservation object.

82
00:05:12,030 --> 00:05:14,550
We're then creating a form validator.

83
00:05:14,820 --> 00:05:18,690
We're making sure that we get the required fields, that we have a minimum length, that an email is

84
00:05:18,690 --> 00:05:19,470
actually an email.

85
00:05:19,620 --> 00:05:21,420
If it's not valid, we take them back.

86
00:05:21,540 --> 00:05:23,790
So here's the part where we want to do something.

87
00:05:24,270 --> 00:05:27,660
We actually want to take them to that reservation summary page.

88
00:05:29,160 --> 00:05:30,670
So how are we going to do that?

89
00:05:30,690 --> 00:05:38,580
Well, first of all, we need to pass this information that we're storing up here over to our reservation

90
00:05:38,580 --> 00:05:39,420
summary page.

91
00:05:40,110 --> 00:05:41,100
So how are we going to do that?

92
00:05:41,130 --> 00:05:43,820
Well, here's a great opportunity to use our session.

93
00:05:44,190 --> 00:05:47,590
So far, we haven't really done anything with the session other than set it up.

94
00:05:48,450 --> 00:05:54,480
So what we're going to do is throw that object, that variable reservation right into the session.

95
00:05:55,050 --> 00:06:00,720
And then when we get to the reservation summary page, we're going to pull that value out of the session

96
00:06:01,050 --> 00:06:03,600
and send it to the template and display the information.

97
00:06:03,990 --> 00:06:09,630
So how do we get something into the session while we have this nice receiver called Repository right

98
00:06:09,630 --> 00:06:10,110
up here?

99
00:06:10,710 --> 00:06:13,110
We can use that M dot.

100
00:06:13,740 --> 00:06:17,190
And what do we have stored inside of that is a lot of stuff.

101
00:06:17,220 --> 00:06:18,870
You can see it all listed here right now.

102
00:06:19,120 --> 00:06:21,990
So what we want is our session.

103
00:06:21,990 --> 00:06:23,070
And where do we store that?

104
00:06:23,070 --> 00:06:29,040
What we store that in app and then we have our session and then we can just put into that session.

105
00:06:29,040 --> 00:06:35,300
And as you can see right here, it requires a context which we have from our from our variable, our

106
00:06:35,900 --> 00:06:41,250
response writer, the key we want to call that thing in the session, which can be whatever we want

107
00:06:41,400 --> 00:06:42,710
and the value we want to store.

108
00:06:43,080 --> 00:06:51,570
So we will put into our context, which we get right out of our response writer, and we'll call this

109
00:06:51,570 --> 00:06:56,730
reservation because it's a reservation and the value will be that variable reservation.

110
00:06:57,180 --> 00:07:00,110
And you think that might be enough and you would be wrong?

111
00:07:00,630 --> 00:07:07,250
We need to tell our application about the kinds of things we're going to store into the session.

112
00:07:07,290 --> 00:07:11,910
The primitives like Int and String, we already can store those that's built right into the sessions

113
00:07:11,910 --> 00:07:12,360
package.

114
00:07:12,990 --> 00:07:17,910
But we actually need to go over to our application main.

115
00:07:20,020 --> 00:07:23,770
Right here, Mango, and we need to add something here.

116
00:07:23,800 --> 00:07:29,480
We need to tell our application that we're going to store certain kinds of values in the session.

117
00:07:29,500 --> 00:07:32,480
So we as I said, we can store primitives.

118
00:07:32,980 --> 00:07:37,280
So what am I going to put in the session?

119
00:07:37,690 --> 00:07:43,600
We can store primitives, but we need to actually tell our application about more complex types, structures

120
00:07:43,600 --> 00:07:47,870
that we've defined ourselves and we want to store in the reservation model.

121
00:07:48,250 --> 00:07:50,760
Now, the syntax to do that sounds a little odd.

122
00:07:51,010 --> 00:07:55,600
It's Gob Gobbi, which is built right into the standard library.

123
00:07:55,600 --> 00:08:01,630
And the method we want is register and register just takes a value, a type of interface, anything

124
00:08:01,630 --> 00:08:03,190
we want to store in our session.

125
00:08:03,190 --> 00:08:06,220
And what we want to store is a model's DORT reservation.

126
00:08:07,060 --> 00:08:11,390
But now that I've done that, I can actually store values in the session.

127
00:08:11,410 --> 00:08:15,100
So back in our handlers here, we've stored the value in the session.

128
00:08:15,370 --> 00:08:16,750
And what do we want to do next?

129
00:08:17,140 --> 00:08:21,850
Well, we could just re display the form, but why am I putting this information in the session at all?

130
00:08:22,840 --> 00:08:27,280
We could just re display a page, but we actually want to do a redirect and the reason we want to do

131
00:08:27,280 --> 00:08:28,810
that is pretty straightforward.

132
00:08:29,770 --> 00:08:33,570
We don't want people to accidentally submit the form twice.

133
00:08:33,580 --> 00:08:40,120
So what we do and this is good standard practice, any time you receive a post request, you should

134
00:08:40,120 --> 00:08:46,900
direct your users to another page with an HTTP redirect and the syntax is right in the standard library.

135
00:08:46,930 --> 00:08:50,910
HDP don't redirect and it requires a few parameters.

136
00:08:50,920 --> 00:08:52,320
The first one is a response rate.

137
00:08:52,330 --> 00:08:53,050
Well, we have that.

138
00:08:53,050 --> 00:08:56,020
It's w the second one is a pointer to a request.

139
00:08:56,020 --> 00:09:02,320
We have that it's per the URL we want to go to is just the direction or where we actually want to redirect

140
00:09:02,320 --> 00:09:04,690
the people and where we want to redirect them to.

141
00:09:04,690 --> 00:09:13,570
Is slash reservation summary Eurail we set up a little while ago and then we need to send a status code

142
00:09:13,570 --> 00:09:20,610
and a good one to use when you're redirecting someone like this is status C other.

143
00:09:20,620 --> 00:09:23,680
So EDP dot status C other.

144
00:09:23,680 --> 00:09:30,340
And you can see right in my preview, that's actually response code 303 and that's the perfect one for

145
00:09:30,340 --> 00:09:30,820
what we're doing.

146
00:09:31,120 --> 00:09:33,970
So will choose that one status the other.

147
00:09:33,970 --> 00:09:34,810
And that's a redirect.

148
00:09:35,560 --> 00:09:36,930
So this should work.

149
00:09:36,940 --> 00:09:42,190
Now, what's missing, of course, is down here in our reservation summary, we're not showing that

150
00:09:42,190 --> 00:09:42,730
page at all.

151
00:09:42,730 --> 00:09:46,420
So I'm just going to show that page and make no changes to it, just to make sure everything works.

152
00:09:46,960 --> 00:09:55,350
So I'll just copy already and copy this, paste it here and put it in the right template, which is

153
00:09:55,360 --> 00:09:57,910
reservation summary page dot.

154
00:09:59,290 --> 00:09:59,620
All right.

155
00:09:59,620 --> 00:10:00,880
So let's stop our application.

156
00:10:00,880 --> 00:10:07,120
If it's running and it is clear, run, go run command website, start orgo.

157
00:10:07,540 --> 00:10:08,560
It's now starting.

158
00:10:08,560 --> 00:10:10,060
So let's go to our Web browser.

159
00:10:11,840 --> 00:10:13,170
So here we are on the Web browser.

160
00:10:13,190 --> 00:10:15,220
Let's make sure that everything works for validation.

161
00:10:15,230 --> 00:10:18,140
It does, and let's populate this with useful information.

162
00:10:18,200 --> 00:10:24,800
A BBC Ask.com and some phone number, and I'll make the reservation.

163
00:10:24,920 --> 00:10:30,530
And what we should see is our make reservation or our reservation summary page with nothing populated

164
00:10:30,530 --> 00:10:33,410
because we haven't actually done anything with the value we're pulling out of the session.

165
00:10:34,960 --> 00:10:35,440
All right.

166
00:10:35,480 --> 00:10:36,270
That looks good.

167
00:10:36,290 --> 00:10:40,500
So let's go back to our code and now let's actually pull the information out of the session.

168
00:10:40,700 --> 00:10:44,670
So how do we get that thing we stored up here?

169
00:10:45,770 --> 00:10:52,400
Here we put in this session, we put an attribute named Reservation that holds our reservation, which

170
00:10:52,400 --> 00:10:54,050
is this right here.

171
00:10:54,380 --> 00:10:55,850
And we need to get it out of the session.

172
00:10:55,880 --> 00:10:56,940
Unfortunately, that's not to hurt.

173
00:10:57,950 --> 00:11:03,380
So let's create a variable reservation and I'm going to create another one.

174
00:11:03,410 --> 00:11:04,040
OK.

175
00:11:04,220 --> 00:11:04,680
OK.

176
00:11:05,570 --> 00:11:06,890
And you'll see why in a minute.

177
00:11:06,890 --> 00:11:08,390
I now I'm going to get this out of the session.

178
00:11:08,390 --> 00:11:17,300
So I go to my m my pointer to a repository and then app and then session and then get and get requires

179
00:11:17,300 --> 00:11:18,920
a few parameters are context.

180
00:11:18,920 --> 00:11:25,400
We know how to get that ARG context and the name of what we want to get, which we called reservation.

181
00:11:26,780 --> 00:11:32,630
Now that's not enough because the session, although it's storing a reservation for us, it has no idea

182
00:11:32,630 --> 00:11:33,890
what type that is.

183
00:11:33,980 --> 00:11:35,660
So we need to type assert.

184
00:11:35,660 --> 00:11:40,500
And that's where the OK that I have at the beginning of this line comes from and we type asserted to

185
00:11:40,730 --> 00:11:42,320
a model's reservation.

186
00:11:43,220 --> 00:11:48,410
Now, if this works, if this type if it's manages to find something called reservation in the session

187
00:11:48,740 --> 00:11:54,380
and it manages to assert it to two type models, reservation, this OK will be true.

188
00:11:54,380 --> 00:11:55,590
Otherwise it's false.

189
00:11:55,880 --> 00:12:00,210
So we need to check to make sure that we actually got it, if not, OK.

190
00:12:00,740 --> 00:12:05,450
In other words, if we didn't get it out of the session the way we're supposed to, we should do something.

191
00:12:05,930 --> 00:12:14,810
So for now, we're going to go log dot print line and cannot get item from a session, will change this

192
00:12:14,810 --> 00:12:16,410
little while and will return.

193
00:12:16,430 --> 00:12:17,570
So we don't want to go any further.

194
00:12:18,020 --> 00:12:23,510
Otherwise we want to do something with this reservation that we successfully pulled out of the session.

195
00:12:23,540 --> 00:12:25,030
And we're going to pass that as template here.

196
00:12:25,190 --> 00:12:31,560
And we already know we have a type in our template data called data, and it holds anything at all.

197
00:12:31,790 --> 00:12:41,630
So let's create a string, a map and we'll call it data equals make map string interface, which is

198
00:12:41,630 --> 00:12:47,360
the type we're using for the data type, and we'll just put a reservation in their data reservation.

199
00:12:47,420 --> 00:12:56,070
That's the key we used to look it up does equal to a reservation and we'll pass that here data.

200
00:12:57,140 --> 00:12:58,070
Now that should work.

201
00:12:58,340 --> 00:13:04,280
Let's go over to our reservation summary page and at the very top of the block named content, and it

202
00:13:04,280 --> 00:13:05,780
has to be within the same block.

203
00:13:06,170 --> 00:13:10,460
We're going to create a variable called Ren's and we'll pull that out of our data variable.

204
00:13:10,460 --> 00:13:13,090
That's part of this template and that's a map.

205
00:13:13,100 --> 00:13:18,680
So we look up things in a map, in goal line templates by using index the map we want to look it up

206
00:13:18,680 --> 00:13:20,480
in, which is called DOT data.

207
00:13:20,510 --> 00:13:23,540
Remember, the DOT says it's something we're pulling out of our template data.

208
00:13:23,990 --> 00:13:25,800
And then what's the key reservation?

209
00:13:26,960 --> 00:13:32,300
Now, if this works, I should be able to come down to this part of my table, the name, and actually

210
00:13:32,300 --> 00:13:32,930
print it out.

211
00:13:33,410 --> 00:13:34,920
Resort first name.

212
00:13:35,000 --> 00:13:35,900
Let's just do that.

213
00:13:35,900 --> 00:13:39,260
And nothing else will stop our application, see if it compiles.

214
00:13:39,560 --> 00:13:40,390
It does.

215
00:13:40,790 --> 00:13:46,280
Let's go back to a Web browser, go back to this screen and we'll just make sure the page is clean or

216
00:13:46,280 --> 00:13:48,780
reloaded and put some data in there.

217
00:13:48,800 --> 00:13:51,560
So, Trevor, that's the only one I'm using.

218
00:13:51,560 --> 00:13:52,900
I'll put Sawalha in there, too.

219
00:13:53,300 --> 00:13:55,140
It's not going to do anything with that except Stort.

220
00:13:55,160 --> 00:13:56,090
We're never going to see it.

221
00:13:56,270 --> 00:14:00,500
But if this works, I should see my first name on the reservation summary page.

222
00:14:01,460 --> 00:14:02,630
Oh, got to give it an email.

223
00:14:03,560 --> 00:14:05,570
See that sitcom?

224
00:14:07,420 --> 00:14:13,540
And there it is, Trevor, perfect, so if I come back here now, I could put the last name in resort

225
00:14:13,550 --> 00:14:15,870
last name and it has to be case sensitive.

226
00:14:15,880 --> 00:14:18,250
You have to match exactly what it's called in the model.

227
00:14:18,430 --> 00:14:19,360
We don't know arrival.

228
00:14:19,360 --> 00:14:20,250
We don't know departure.

229
00:14:20,260 --> 00:14:21,120
We do know the email.

230
00:14:22,360 --> 00:14:28,240
So resort email and we also know the phone rings, dog phone.

231
00:14:28,660 --> 00:14:31,240
So let's save this and I shouldn't have to restart the application.

232
00:14:31,240 --> 00:14:32,920
So I just made a change to the template.

233
00:14:32,920 --> 00:14:33,670
But I'll go back.

234
00:14:34,330 --> 00:14:39,190
I'll make sure I'm on the make reservation page and the form is now being populated.

235
00:14:39,220 --> 00:14:47,890
Trevor Sawalha me at here, Dotcom and my phone number is five five five five five five five five five

236
00:14:47,890 --> 00:14:48,270
five.

237
00:14:49,210 --> 00:14:50,230
And let's see what happens.

238
00:14:51,010 --> 00:14:52,360
And there it is, everything.

239
00:14:52,360 --> 00:14:55,150
One, two, three, four pieces of data all displayed.

240
00:14:55,540 --> 00:14:56,680
Now, this is a good start.

241
00:14:57,310 --> 00:14:59,200
There's a couple of other things I want to do, though.

242
00:14:59,590 --> 00:15:01,200
So let's go back to our code and look at it.

243
00:15:01,220 --> 00:15:03,040
We'll do these in the next lecture, not in this way.

244
00:15:03,490 --> 00:15:10,240
So other handlers, when I actually handle the post of Make Reservation, which is right here, that's

245
00:15:10,240 --> 00:15:10,480
OK.

246
00:15:10,480 --> 00:15:13,810
I pass the form, I create my reservation, I do my valid testing.

247
00:15:14,200 --> 00:15:14,620
Good.

248
00:15:14,620 --> 00:15:16,540
And we go over to the reservation summary page.

249
00:15:16,540 --> 00:15:17,130
No problem.

250
00:15:17,140 --> 00:15:18,600
So we now get redirected.

251
00:15:18,650 --> 00:15:19,570
Reservation summary.

252
00:15:20,080 --> 00:15:21,430
This is the part I'm interested in.

253
00:15:21,910 --> 00:15:30,040
What if someone somehow goes to our site slash reservation dash summary without making a reservation?

254
00:15:30,370 --> 00:15:34,120
At that point, this variable will not be valid.

255
00:15:34,150 --> 00:15:36,970
This will be false because it can't pull anything out of the session.

256
00:15:37,690 --> 00:15:40,240
What I'm doing right now is effectively showing a blank page.

257
00:15:40,810 --> 00:15:46,630
If I go to this page without a reservation in the session, it just writes to my log file, which is

258
00:15:46,630 --> 00:15:51,070
just the terminal in our case, returns a blank screen and it appears that nothing happened.

259
00:15:51,370 --> 00:15:57,610
What we should do is redirect them somewhere else on the page and actually give them a message, an

260
00:15:57,610 --> 00:15:58,810
error message somehow.

261
00:15:59,110 --> 00:15:59,890
And we're going to do that.

262
00:15:59,890 --> 00:16:03,940
We're going to redirect them to the home page and we'll use Nottie to display an error message.

263
00:16:04,600 --> 00:16:09,430
So we'll take care of that in the next lecture and then we'll move on probably to test it.
