So let's look at where we are right now.
I'm going to make sure my application is running and just see what we have to do next.
So I start the application.
I go over to my favorite browser and choose the homepage, which is where I am, and make a reservation,
choose any two dates, because I know that will show me something that's valuable and search.
So we're here and I want this to be clickable.
I want that to be a click.
When I click on Generals' quarters, it takes me off the reservation page and before it shows me the
page, it actually stores the fact that I want to stay in the generals quarters in my social variable
called reservation that we did last time.
So let's go back to the template and create a link.
So I'm going to open up my template, choose room and I maybe will make this an unordered list for right
now.
So I'll wrap this whole thing in a U-Haul tag, which eventually I'll get to be able to typewrite.
Get rid of that and put my closing, you will tag here and inside of here, the room name should be
wrapped in an L.A. tag.
And I want this to be a link, so what do I want this link to be?
It can be anything I want, but I want to make sure that the link includes the ID of the room that is
currently displaying.
And I know I have that in the ID of the individual entries that I see as arranged through Rum's.
So I can just say a F equals and I'll call this Chew's room, followed by the ID, which is Daudt ID
and I just wrap it in my double curly braces so it pulls it out of the current iteration of the room's
variable and ranging through and shows it there.
And then I can just close this, opening a tag and of course close the whole attack right there so that
when I, when I reload this page, if I save this and go back, I might be able to just reload here
and say resend and there it is.
Not quite right.
So I've got a typo in there somewhere.
Yes, there it is.
Let's put that there.
Save this looks right now.
Reload this and I still have an extra tag somewhere.
There it is.
All right, that looks better now that I've created this Eurail choose dash room, followed by a number
I need to create a route for it.
So let's go back to our roots file and see how we're going to do that, because we haven't done this
yet.
So roots, they're there.
I want to create a new route mux.
It's a get route because I'm just clicking on a link to Choose Dasch room, and then I want the idea
to go in there.
And how am I going to do that?
Well, the nice thing about this router, Krutch, the China key router is I can just do this, put
parentheses around the a variable name of my own choosing.
It could be whatever I wanted, but I chose it because it's a remedy.
And what this route will match is choose Dasch room slash anything.
And I want that to go to Handler's repo.
And I'm need to create a new method or new function called Choose Room, which I will do right now.
So let's go over to our handlers and create a new function, which I will call func.
And it's going to have the repository receiver because I'm going to be using that and I'm calling it
to choose room.
And it takes a W, which is an active response writer and a pointer to a request and cdpr dot request.
Now request.
OK, so now I have this function, so my roots shouldn't show an error now, and it does not, what
do I want to do in this function?
Well, the very first thing I want to do is to get this part of the URL, the ID right here.
I want to read that from the actual Eurail and receiving and store it as my remedy.
That's the room that I'm currently choosing.
So if this shows the general's quarters with an ID of one and somebody clicks on the link, I want to
get the one.
If they click on the major suite, which is an idea of two, this will be a two.
When I click on it, I want to get the two.
So let's go back to our handlers and see how we do that.
Now, the nice thing about Chey is it has some helper methods that allows us to do this.
So I'll say room ID, which is what I'm going to call the variable.
And potentially an error is equal to sturgeons.
We're going to convert a string from a into an integer, a two high.
And inside of that, I'm going to call the helper function built into the router.
So Chey dot Eurail Perram.
You are L Perram.
There it is.
And that requires two arguments.
It requires our request, which I have, and it requires the key, which is exactly what I called it
in the Roots file.
So I chose ID here because over in Roots it's ID inside those curly braces.
So now I have the remedy that I need to check for an error.
If error is not equal to nil, I'll just display a server error helper's server error W and then error
and return.
OK, so now I have my remedy and what am I going to do with that.
Well I need to get that reservation variable I stored in the session somewhere in this function.
I need to pull it out of the session.
I need to update room ID which has a default value of zero.
Stick the room ID in that correct place in that variable and then put the reservation back in session.
So let's get the reservation rez and let's just see what we have, what are what we're going to return
values our first.
So I'll say Emden app.
Dort session doget, and it requires the context, ARGT context, as usual, and it requires the key
and the key I'm looking for is reservation and I'm pulling that out of there.
Is that enough?
Well, let's look at this jet function again.
We haven't done this in a while, so it might be worthwhile looking at, again, get returns, the value
for a given key from the session data.
The return value has the type interface.
Well, that's not good.
I needed to be of type models, stock reservation.
So we usually need to be type asserted before you can use it.
For example, let's copy this example, OK, and go back to our handler and just paste it right below
this and then modify it as necessary.
First of all, let's get rid of the comments and format everything.
And I will call this rez for reservation.
And it's not coming out of session.
It's coming out of Emden app dot session.
And I'm not casting it to a string.
I'm casting it to a model's reservation that are spell models.
Right.
Reservation.
And it's not just ah, I need to get the context from our context.
So now I've actually built this up and I have my reservation variable stored.
I'm not using it yet and I have a not OK and not OK here.
I can just do a server error.
Something went wrong that's sufficient for right now.
Now that I have this reservation, what do I want to do with it?
I want to update the room ID to this variable remedy.
I just do that by saying resort remedy equals ridi and then I put it back in the session and I can do
that the same way I did up here.
I can just up in one of the functions above.
I'll just type it out.
MoCap app session put and it requires the context, art context and it requires the key which I have
to make exactly the same as I used before.
And the value is Rets.
Now I've put that back in session.
So once they've clicked on this, what do I want to do next?
At this point, I want to display the Make Reservation page so I can do that really easily.
Let's find out how we display that reservation page, which is right up.
Well, we'll do from the Roots files faster to get it that way.
Make reservation.
It's this page I want it to want to show so I can just redirect them to that page at this point.
OK, so I'm going to copy that.
You orl go back to choose room in my handlers, which is right here, the very bottom and paste.
Oh sorry.
Put in htp dot redirect which is right here.
And it requires the W, the R, the Eurail, which I'll paste in and the code HDB dot status C other
because it's in 300 range and that's a nice useful one.
All the other 300 ranges probably are inappropriate, and that's all I have to do.
I think.
Let's start our application.
So stop it.
Start it.
Did it compile?
Yeah, it compiled let's go back to our Web browser and let's go back to the home page and start this
process right from the beginning.
Make a reservation now.
So I'm searching for any two dates.
Doesn't matter what they are in this case, because everything's available except for that little range
in February.
So I searched for it and then I click on Generals' quarters.
All right.
Didn't quite work.
What went wrong?
Well, let's find out.
So I get this.
Are there anything is there anything in the log file?
There is.
There is an error there.
All right.
The error is invalid memory address or nil pointer dereference in here from internal helpers, from
handlers.
Dok go.
Let's see what that line is.
Ah OK.
Here I made a mistake.
I left Fux in there.
I'm not getting a reservation out of the session.
I'm saying results.
OK is reser invasion and then this line gets deleted altogether.
So that was my mistake.
Happens sometimes.
Let's clear the screen and run it again.
And try again, so we'll go back one screen, back one screen, reload this page, put in two dates
just to make sure that it's getting the values and search.
And this time I click on Major Sweep.
That looks better.
So now I need to fix this screen up.
What I want to display next is I want to get rid of start date, end date and the hidden field that
I have down here.
Well, I might I shall leave that hidden field, but I'll probably have to work on it a little bit up
at the top underneath where it says reservation details.
I want to put start date and date and the room names and then ask for their first name, last name,
email and phone.
All right.
We'll take care of that in the next lecture.