OK, so this time around, we want to get this form when we submit it with all proper data.
So anything that will pass validation is suitable for right now.
We don't want it to display this blank screen.
We want it to display a reservation summary.
So that shows the user what they're registered for.
We're giving them a confirmation, basically.
And again, we don't have enough information on the form right now.
We don't know what room they're in.
We're not bothering to display the dates of the reservation, but we'll get to that right now.
We're just going to get things up and running as a kind of wireframe.
So the first thing I'm going to need, obviously, is somewhere near my templates.
I'm going to create a new template and I will call that new file, not a go file.
I will call it reservation summary page, Dot Key and Peele.
And this is just going to be a summary page so I can go to the about page, for example, and just copy
everything in there to give it a kind of starter.
So we're going to have information display and we want a title.
So let's give this title.
We'll push the title down a little bit by giving it a class of MTV five.
That's one of the bootstrap building classes that pushes it down from the top of the page.
So it's not quite so crowded.
And we'll just call the title reservation summary.
All right, now, underneath that, I'm going to put an H.R., just a nice line, and then I'm going
to create a table, which you haven't done yet.
You may have done it, but some of you may not have done it.
So let's build a table and a table is built just using standard HTML like this.
It's a table.
And I'm going to use one of the classes are some of the classes built into Bootstrap to make it a little
prettier.
So bootstraps default class for table is not surprisingly called table.
So that'll apply default bootstrap styling to it and then I'll make it striped just so it's easier to
read tables straight.
OK, so there is a table tag now.
A table typically has a head.
Those would be column headings, the top of the table.
But I'm going to leave an empty one in there because I don't really need it.
I'll put it in just because it's nice to have it.
And then it has a body which is called Tibaldi.
And inside of that you have rows and columns and we're going to have a row.
So we'll make one row.
And inside of that will make a column inside of that row TD and we'll give it a label name.
And we don't actually know how to get the name here yet, but we're going to put it in a column right
beside.
And I'm going to copy this and paste it for the other three pieces of data.
So we're going to have their arrival, which we don't know yet.
We're going to have their departure, which we don't know yet.
We're going to have their email, which we do know and we're going to other phone.
So we'll put arrival and departure.
And email and phone, OK, so there is enough information for us right now.
We'll be able to display some of the content that we have from our posted form.
And we're going to populate this with that information, with the bits we know right now.
We don't know arrival and departure, but we're going to get there eventually.
So I'll put them in as placeholders.
Great.
So I've created this this template.
Now I need a handler to display that template.
So let's go to our handlers and let's just create one cold.
We'll put it right at the bottom.
I'll call it funk.
And again, it's going to be linked to a receiver for a repository and I'll call it, oh, reservations,
memory.
And because it's a handler has to take a writer, HTP response writer and it has to take a pointer to
an umpire, a pointer to an update request there.
We have a handler now.
So let's go to our roots file and create a route for that that's under command web routes.
So we'll put this near the reservation stuff right here.
Is good a place as any and it will be a get request reservation summary and it will point to our handlers
in our repository repo the reservation summary there.
So now we have a route to it.
That's great.
So let's go back to our handler for a minute and think about how we're going to get from back to roots,
how we're going to get from this post of search availability to this get a reservation summary.
So in other words, they're posting the form here, which is post availability, not post availability.
RM1 forms route's.
From here, so reservation summary, it doesn't belong here.
Let's get it out of there and put it down here.
We're making a reservation.
So in other words, let's try this again.
We're going from post reservation and we want to get to reservation summary.
So let's go to post reservation and see what we're doing.
So we're parsing the form.
We're building our reservation object.
We're then creating a form validator.
We're making sure that we get the required fields, that we have a minimum length, that an email is
actually an email.
If it's not valid, we take them back.
So here's the part where we want to do something.
We actually want to take them to that reservation summary page.
So how are we going to do that?
Well, first of all, we need to pass this information that we're storing up here over to our reservation
summary page.
So how are we going to do that?
Well, here's a great opportunity to use our session.
So far, we haven't really done anything with the session other than set it up.
So what we're going to do is throw that object, that variable reservation right into the session.
And then when we get to the reservation summary page, we're going to pull that value out of the session
and send it to the template and display the information.
So how do we get something into the session while we have this nice receiver called Repository right
up here?
We can use that M dot.
And what do we have stored inside of that is a lot of stuff.
You can see it all listed here right now.
So what we want is our session.
And where do we store that?
What we store that in app and then we have our session and then we can just put into that session.
And as you can see right here, it requires a context which we have from our from our variable, our
response writer, the key we want to call that thing in the session, which can be whatever we want
and the value we want to store.
So we will put into our context, which we get right out of our response writer, and we'll call this
reservation because it's a reservation and the value will be that variable reservation.
And you think that might be enough and you would be wrong?
We need to tell our application about the kinds of things we're going to store into the session.
The primitives like Int and String, we already can store those that's built right into the sessions
package.
But we actually need to go over to our application main.
Right here, Mango, and we need to add something here.
We need to tell our application that we're going to store certain kinds of values in the session.
So we as I said, we can store primitives.
So what am I going to put in the session?
We can store primitives, but we need to actually tell our application about more complex types, structures
that we've defined ourselves and we want to store in the reservation model.
Now, the syntax to do that sounds a little odd.
It's Gob Gobbi, which is built right into the standard library.
And the method we want is register and register just takes a value, a type of interface, anything
we want to store in our session.
And what we want to store is a model's DORT reservation.
But now that I've done that, I can actually store values in the session.
So back in our handlers here, we've stored the value in the session.
And what do we want to do next?
Well, we could just re display the form, but why am I putting this information in the session at all?
We could just re display a page, but we actually want to do a redirect and the reason we want to do
that is pretty straightforward.
We don't want people to accidentally submit the form twice.
So what we do and this is good standard practice, any time you receive a post request, you should
direct your users to another page with an HTTP redirect and the syntax is right in the standard library.
HDP don't redirect and it requires a few parameters.
The first one is a response rate.
Well, we have that.
It's w the second one is a pointer to a request.
We have that it's per the URL we want to go to is just the direction or where we actually want to redirect
the people and where we want to redirect them to.
Is slash reservation summary Eurail we set up a little while ago and then we need to send a status code
and a good one to use when you're redirecting someone like this is status C other.
So EDP dot status C other.
And you can see right in my preview, that's actually response code 303 and that's the perfect one for
what we're doing.
So will choose that one status the other.
And that's a redirect.
So this should work.
Now, what's missing, of course, is down here in our reservation summary, we're not showing that
page at all.
So I'm just going to show that page and make no changes to it, just to make sure everything works.
So I'll just copy already and copy this, paste it here and put it in the right template, which is
reservation summary page dot.
All right.
So let's stop our application.
If it's running and it is clear, run, go run command website, start orgo.
It's now starting.
So let's go to our Web browser.
So here we are on the Web browser.
Let's make sure that everything works for validation.
It does, and let's populate this with useful information.
A BBC Ask.com and some phone number, and I'll make the reservation.
And what we should see is our make reservation or our reservation summary page with nothing populated
because we haven't actually done anything with the value we're pulling out of the session.
All right.
That looks good.
So let's go back to our code and now let's actually pull the information out of the session.
So how do we get that thing we stored up here?
Here we put in this session, we put an attribute named Reservation that holds our reservation, which
is this right here.
And we need to get it out of the session.
Unfortunately, that's not to hurt.
So let's create a variable reservation and I'm going to create another one.
OK.
And you'll see why in a minute.
I now I'm going to get this out of the session.
So I go to my m my pointer to a repository and then app and then session and then get and get requires
a few parameters are context.
We know how to get that ARG context and the name of what we want to get, which we called reservation.
Now that's not enough because the session, although it's storing a reservation for us, it has no idea
what type that is.
So we need to type assert.
And that's where the OK that I have at the beginning of this line comes from and we type asserted to
a model's reservation.
Now, if this works, if this type if it's manages to find something called reservation in the session
and it manages to assert it to two type models, reservation, this OK will be true.
Otherwise it's false.
So we need to check to make sure that we actually got it, if not, OK.
In other words, if we didn't get it out of the session the way we're supposed to, we should do something.
So for now, we're going to go log dot print line and cannot get item from a session, will change this
little while and will return.
So we don't want to go any further.
Otherwise we want to do something with this reservation that we successfully pulled out of the session.
And we're going to pass that as template here.
And we already know we have a type in our template data called data, and it holds anything at all.
So let's create a string, a map and we'll call it data equals make map string interface, which is
the type we're using for the data type, and we'll just put a reservation in their data reservation.
That's the key we used to look it up does equal to a reservation and we'll pass that here data.
Now that should work.
Let's go over to our reservation summary page and at the very top of the block named content, and it
has to be within the same block.
We're going to create a variable called Ren's and we'll pull that out of our data variable.
That's part of this template and that's a map.
So we look up things in a map, in goal line templates by using index the map we want to look it up
in, which is called DOT data.
Remember, the DOT says it's something we're pulling out of our template data.
And then what's the key reservation?
Now, if this works, I should be able to come down to this part of my table, the name, and actually
print it out.
Resort first name.
Let's just do that.
And nothing else will stop our application, see if it compiles.
It does.
Let's go back to a Web browser, go back to this screen and we'll just make sure the page is clean or
reloaded and put some data in there.
So, Trevor, that's the only one I'm using.
I'll put Sawalha in there, too.
It's not going to do anything with that except Stort.
We're never going to see it.
But if this works, I should see my first name on the reservation summary page.
Oh, got to give it an email.
See that sitcom?
And there it is, Trevor, perfect, so if I come back here now, I could put the last name in resort
last name and it has to be case sensitive.
You have to match exactly what it's called in the model.
We don't know arrival.
We don't know departure.
We do know the email.
So resort email and we also know the phone rings, dog phone.
So let's save this and I shouldn't have to restart the application.
So I just made a change to the template.
But I'll go back.
I'll make sure I'm on the make reservation page and the form is now being populated.
Trevor Sawalha me at here, Dotcom and my phone number is five five five five five five five five five
five.
And let's see what happens.
And there it is, everything.
One, two, three, four pieces of data all displayed.
Now, this is a good start.
There's a couple of other things I want to do, though.
So let's go back to our code and look at it.
We'll do these in the next lecture, not in this way.
So other handlers, when I actually handle the post of Make Reservation, which is right here, that's
OK.
I pass the form, I create my reservation, I do my valid testing.
Good.
And we go over to the reservation summary page.
No problem.
So we now get redirected.
Reservation summary.
This is the part I'm interested in.
What if someone somehow goes to our site slash reservation dash summary without making a reservation?
At that point, this variable will not be valid.
This will be false because it can't pull anything out of the session.
What I'm doing right now is effectively showing a blank page.
If I go to this page without a reservation in the session, it just writes to my log file, which is
just the terminal in our case, returns a blank screen and it appears that nothing happened.
What we should do is redirect them somewhere else on the page and actually give them a message, an
error message somehow.
And we're going to do that.
We're going to redirect them to the home page and we'll use Nottie to display an error message.
So we'll take care of that in the next lecture and then we'll move on probably to test it.