So what we want to do this time around is to finish up this screen, so I'm going to search for a reservation
and I will choose the 25th and the twenty sixth as my start and end dates and click on a room.
And I want this to disappear, start date and end date.
And I want it to appear up here as Nona editable text.
I also want to display the wrong name.
And finally I want to be able to make the reservation.
So let's look at how we're displaying this page right now.
Make reservations.
So that's the URL.
Make a reservation.
Let's go back to our code and look at our roots and look at make reservation and see what's happening
in that particular function.
So it looks like what we're doing is creating an empty reservation and then just passing that to the
template along with an empty form.
Well, we already have a reservation and that reservation has most of the information we already need.
So why don't we do something useful with that instead, instead of taking it, creating an empty one,
let's pull the reservation out of the session.
And we did that just a little while ago.
So we did that in this function, which is choose room.
So let's find that here is where we pulled the reservation out of the room, right out of the session,
pulled the reservation out of the session.
So let's copy that.
Go back to our Make Reservation page, get rid of this empty reservation and instead pull one out of
the session and Rez will get stored in reservation.
And here we can't generate a printing error because we technically don't have one.
We just have a true or false for.
OK, so I'll fix that just by saying errors DOD knew and saying I cannot get a reservation from again
from session.
And you're not supposed to start an error message with a capital letter for reasons I've never understood.
But there you go.
All right.
So that fixes that.
Now we have this information.
Is that everything we need?
Let's find out.
Let's go over to our Make Reservation page and see what changes we have to make down here.
I don't need start date and end date anymore.
They have the names of start date and end date.
I don't need those.
Instead, I want to display them up here, but I still need them in the form.
So maybe I'll put them in his hidden fields.
Input type equals hidden naming will start date and value equals and what you might be thinking you
could do.
It's just this resort start date because we have the reservation.
There should be a period, not a comma.
We have the reservation.
We got it right here.
We pulled it out of our date, a variable from the template data and we know it's a reservation.
We can just display reservation start date.
You might think that, but you'd be wrong.
I'm going to duplicate this anyway and just get my end date set up because I'm going to need those in
a minute.
And this would be end date.
But that won't work.
And I won't work because don't forget, if you look at template or look at the models, let's open that
up.
Models don't go and you look at a reservation.
Start date and end date aren't in the right format.
They are stored in whatever go uses for time time.
So they won't display in the format that I need them to display in, which is for your four digit eard
hyphen, two digit month hyphen, two digit day.
So what we need to do is effectively the reverse of what we did some time ago, and that is to take
a time and cast it back into a string in the format we want.
And fortunately, that's really easy.
So at this point, I've pulled my rez out of the session.
That's my reservation.
So I'm going to say SD for start date is assigned the value of rez dot start date.
Then I'll just call the format function, which is built right into the time time and give it the correct
layout.
And if you recall, this is the correct layout.
So that should give me the year, the month and the day, and I can duplicate that and do the same thing
for Endi, which I'll call it change this to end date.
Try that again and date.
Now I have them in strings, but how do I get them from here down to here?
I could stick them in data that would work.
But we already if you look at the template data, we have this string map in the format in our struct,
in our type of template data, we have a string map, so let's use that.
So go back to here.
I'll create a string map, which I'll call string map.
I will assign that the value of make the map string string and then I just assign my start date an end
to it.
So I'll say string map start date is equal to SD and string map.
End date is equal to it, and then I just passed my stirring map as part of my template here because
that type is already there.
We've already added that to the the type template data and we just put our spring map in there.
All right.
So I have that.
Now, let's go back to our reservation page and display some information.
So right now, I can just say in a new paragraph now it comes after reservation details.
I'll use this existing paragraph.
I'll put a line break there and I'll just say a rival.
And then print out from my string map index dot string map, which has a capital M and I called it Start
Underscore Date and I'll copy this whole thing because I'm going to use it in a minute and put a line
break there.
And I replace the start date in here with what I just copy and we'll do the same thing for the end date.
Which I'm going to call departure.
And I'll paste that and change this to end it and paste it in here, actually, I'll just copy the whole
thing that I remember if I copied the curly brackets or not.
And this way I know I'm getting the right thing and pasted in there.
The other thing that we had was a hidden field down here for remedy and remedy is hard coded to one
which isn't very helpful for us.
Fortunately, that's not hard to change either.
So I'm going to change my remedy from the hardcoded value of one to from my reservation variable, which
I got right here, dot room ID.
So if I save that and go back, start my start my applications, I'll clear this, clear the screen,
I'll start my application.
Clear the screen.
Run my application.
And go back to my Web browser and start the whole process over, so click on Make Reservation now choose
and remember the dates I'm choosing 25th and 26th searching.
I'm going to choose major suite, which I know is 82.
I can see that right down in the lower left hand corner of the window.
And there it is.
So it shows me reservation details, arrival.
There's a date.
And I could use whatever format I wanted there.
If I wanted to make it like Thursday, the 25th of November to 2020.
I can format that using my format string in my handler and there's my departure.
That's correct.
I have a room.
It is a hidden field.
Let's make sure.
So let's find room ID.
There it is Editta.
All of that is correct.
The one thing that's missing at this point is the name of the room.
And although technically this will work without it, it would be really helpful if I could display the
room name at the very top, say, between the title and the arrival date.
Can I do that?
Well, let's go look at our model.
So what we have in the actual models, I mean, hi, this
is I have under a reservation, I have the ID, the first name, the last name, the email, the phone,
the start date, the remedy.
I don't have a room name, but I do have this type room which is of type models, dot room right here
and I'm not using it and I know the name of the room at one point during this entire process.
So is it possible that I could populate just the room name field of this room type named room and then
draw it out in my template?
I think it is.
Let's figure out where we could put that.
So let's think about the process.
When I click on the room, I am clicking on Choose Room right here.
Right.
Choose from right here.
Is it in there?
Let's find out in here.
I get the room ID and then I have a reservation which I pull from the court from the session.
So don't I actually don't have it at this point.
At no point in this process do I have the name of the room.
I have it back when I'm searching.
So if we go back here and say search availability, when I post it, I have it right here, but I don't
know which room they're going to choose.
So it seems to me like we're going to have to write another database function to actually go get a room
by ID.
And fortunately, that's really easy.
So let's go over to our where is it here?
It's under internal repository postgrads Digo.
Right here.
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
a room by ID.
So I will call this func with a receiver of type Postgres DB repo.
I'll say get room.
By I.D., that will be the name of the function, which seems to make sense because that's precisely
what I'm trying to do and it's going to take one parameter, which I'll call ID of type it, and it
will return a model's dot room and it potentially will return an error.
So as I usually do, I'm not going to type out this contact stuff because I almost always get it wrong.
I will copy and paste it and I'll declare a new variable.
VAR are a room of type models dot room.
Then I'll write a query.
My query is going to be equal to Inditex just so I can format it.
However I want select and what's in our room table.
Well let's not guess.
Let's go look.
So I will just pull up my post right here, go to rooms and look at the structure ID room name created
an updated app.
Couldn't be simpler.
Let's go back select ID room name created at updated at from rooms where ID equals dollar sign one.
That's my query.
And since I'm only getting one row I may as well use the query contact query row context.
So row is assigned the value of mpeg db dot query row context, which takes the context which I have
at the very top of this function and my query and my arguments, my one placeholder, which is called
ID, which I receive as a parameter right up here, and then I actually get my error when I try to scan
this row, row, dot scan and I scan it into a variable that I've declared up here but haven't done
anything with yet.
So I'll put room of ampersand.
You got to use a reference to it.
Room ID is my first one room board name is my room name, which is my second one.
And then room dot created art and room updated up there.
So now I have this.
I need to check for my error.
If error is not equal to nil, then what do I do.
I return my variable room and the error, otherwise I return my room and nil because there was no error
and that should do it.
Let's give this a comment.
Gets a room by ID.
And then we need to put this in our repository, so let's get back there, which is under Postgres,
we need to copy this, paste it into our repository so it becomes available, make sure everything compiles.
It does good.
OK, I'll stop the application and now let's go use this.
So back in our handlers, which are right here, when do I want to use this?
I want to use this just before I display the make reservation page.
So let's go back to our roots to get back to the function right here.
At this point, I know the reservation and I know everything I need to know.
All I have to do is to look up the room and store its name in the appropriate location.
In my reservation.
My reservation, so I can do here is actually just say now that I have my reservation, I can say room
or error is a sign.
The value of IMDB, get Rambhai ID and pass it Ransdorf Brumidi.
So now I have if this works as I hope it will, I will have everything about that room stored in this
variable and potentially I have an error, so I've got to check for that.
If error is not equal to nil helper's dot server error, W. error return.
Otherwise I have it and I can just in my reservation I can store the room name so I can say red dot
room dot room name equals room dot room name.
And now I've populated that variable which is of type models.
Dot reservation.
I populated its member room which is a type models dot room.
I've only populated one field but that's all I care about right now.
So I'll just store that in there and we should be good to go because I put this variable in the session
down here.
So if I go back to the make reservation page now at the very top, I can say room and I can just go
rez, which I'm going to have to move something in a second.
But don't worry, I will resort room, dot room name and I can't call this yet.
And actually this helpfully underlines it red showing me because I don't actually declare this variable
until later.
So let's just cut that and move it right up here.
And now that won't be an issue anymore.
And I need to put a carriage return after this, otherwise these will be on the same line.
So I put a line break there and I should be able to stop the application, which has already stopped.
Run it again and try this one more time.
So let's go back here and start over from the homepage and choose make reservation now and search for
availability.
So I'll go the 26th to the 27th this time search, choose the major suite and it shows me the room is
the major suite.
Perfect.
Now let's make sure the last part works.
So I'll put Mary Jones Mary at Jones dot com and some phone number.
And make the reservation and hopefully we haven't broken anything.
Looks good.
We're going to have to change this, of course, the reservation summary page to include the room,
to include the arrival date and include the departure date.
But that should be trivial.
All right.
We'll take care of that last step and a few other minor things that we need to think about, for example,
when I'm searching for a reservation.
Should I be able to choose a date in the past?
Probably not, unless time travel has recently been invented.
That's probably a very bad idea.
So I should modify this calendar such that no date before either today or tomorrow or whatever we decide
the first date should be is even selectable.
And then we're also going to want to probably put server side validation in to make sure that they didn't
turn off JavaScript manually, type in a date in the past, but in the correct format and then submit
the submit the page.
So we're going to want to take care of that as well.
But these are minor things.
They're easy to clean up and we'll take care of that in the next lecture or two.