So now we want to create some code that will allow us to click on a reservation either from this screen,
new reservations or from this screen all reservations and display it.
And I'm going to display it in a form.
So if I want to make changes to it, I can.
And I'm also going to at some point add the functionality to mark a reservation as processed, which
means it will no longer show up on this screen because it will no longer be a new reservation.
So to do that, I'm going to need obviously a handler.
I'm going to need some method of pulling a single reservation out of the database, and I'm going to
need to update the template and change my routes.
So let's get started.
We'll go creating a stub handler first.
So let me go to my Edem and find my handlers here, there.
And let's create a handler that shows one reservation.
First of all, let me add a comment to this, because I didn't do that displays the reservation calendar,
which we're going to get to eventually.
But right now we want to have a handler which has the receiver of type pointer to repository and I'll
call it admin show reservation and it will take a response writer.
And a pointer to a request.
OK, and we'll have it render a template, so I'll just copy this line just to make things a little
faster and paste it in here and I'll call it admin reservation.
It's show and then I'll copy this name and create that template in my templates folder.
New file paste, because I didn't copy the name admin reservations showed up paged at Temple.
And I'll add it to my repository and I will simply put in a copy, something from the dashboard, their
copy this and paste it in here and put this as show reservation just as a placeholder to make sure it
works.
And I'll give the title reservation.
All right.
So we created that handler.
Now let's go create our route.
So we called the handler at Minshall Reservation.
Let's give it a comment.
Shows the registration reservation in the admin tool.
OK, so let's copy the name and go to our roots and create a route for it.
So again, this is going to be in the protected part of our application.
And I'll put in Mark Start yet.
And for a path name, I think I'll use reservations, reservations, because the admin part is added
automatically.
And then I'm going to have the source and remember that on our new reservations page, the link was
admin reservations, knew the ID and on our all reservations page it all ID.
So I need to have a route that actually has a placeholder in it.
So one the first one will be all or new for now.
So I'll call that SIRC for source where we're coming from and then I'll put ID.
And again, because those are matching parameters or matching parts of our route, I enclose them in
curly brackets and then I want to want to go to Handler's Repo dot admin show reservation.
I think it was.
Yeah, I'm in show reservation.
OK, so we have our route set up, so let's try running this.
So I'll stop my application, run my application just to make sure it works and go back to my mental
reload the page and just click on one reservation.
And there it is.
It's showing the reservation.
Great.
So that's a good start, but it's obviously not enough.
We need to grab information from the database in order to show it on this page.
So right here in our handlers, when I'm showing the reservation, I need to get a reservation from
the database.
So how am I going to do that?
Well, I'm going to open up my postcrisis postgrads, Dongo, and at the very bottom, I'll create a
new function and I'll call it.
Will has to have the receiver of Postgrads DB Repo and I'll call it, um, get one reservation.
I think that's probably a good name.
Now let's call it get reservation by ID, which is exactly what I'm doing here.
And I need to have a parameter which is the ID of type INT and I'm going to return to things, a model
DOT reservation and potentially an error.
OK, so as I always do, I'm going to go copy the context from up here.
I just don't like typing that out and paste it in, and then I'll create a variable which I'll call
Rez of type models, dot reservation to hold the information I'm going to pull from the database.
Now let's write the query and this is a simple select statement.
Query is assigned the value of in back ticks select and because this is a reservation, it's going to
have that room model as part of this struct.
So I'll use an alias.
Our ID Arnaut first name are being an alias to the reservations table.
Our last name, Arnaut email, Arnaut phone Arde start date and I'll go on to the next line just to
make this a little more readable.
Are not end are not room id are not created at are not updated that are processed which is the column
we added in the last lecture or recently anyway.
And then R.M., I'm getting the room information, R.M. ID our room name and again I don't care about
the created or updated at forums so I'll ignore those.
And I'm selecting that from reservations with the alias of our and I'm going to left join rooms R.M.
on our dot room ID equals R.M. ID, which uses that foreign key relationship to join these two tables
together.
And finally my Where clause.
I want this only for one particular ID.
So where are for the reservations table ID equals and my placeholder dollar sign one.
So that should be my query.
Let's make sure we've got it right.
Select Arnaut ID our first name, our last name.
Aadhar email are not from our start date, are not end date, are not remedy, are not created utada
updated, ate and processed.
That's all for the the reservations table.
And then our amde id and our room name.
Yeah that looks right to me.
So this is one record we're getting at most one.
If it finds one little return, one if it finds nothing, well there'll be nothing to stamp so we can
use our query row context which returns one row DB query row context, handed the context handler query
and handed the ID, which is substituted for that same one.
So that's our database query and then we try to scan this into our res variable.
So error is assigned the value of row dot scan and as I always do, I'll put this on separate line so
it's easier to read and I'm going to scan it into the variable.
And the first thing I'm getting from my query is the ID.
Now duplicate that a bunch of times just to make it faster.
The next thing is first name, then the last name, then email, then phone, then start date.
Then end date.
Then room ID.
And a few more duplications.
Then created that, then updated and then processed, and I think there's two more room ID and room
name, so room ID and room dot room name and we check for our error.
If error is not equal to nil, then something went wrong.
Probably it couldn't find that ID and we'll just return our rez and the error.
Otherwise everything worked as expected.
So we'll return Rez and Nhill and that should be it.
So let's copy this and give it a comment.
Returns one reservation.
By ID and then we'll copy the whole thing here and put it in our repository, so let's find a repository
and paste that in and then again copy the whole thing and put it on our test repo and simplify it as
much as possible.
Test repo all the way down here, paste it in.
We don't need any of this stuff and we don't need the context and it has to have the correct receiver.
All right.
Let's make sure this compiles.
Good comp. No problem, so let's go back to our handler and grab this reservation.
Now, how are we going to get this reservation?
Remember, it's at the end of the URL.
So there's actually two things I want to pull out of this show reservation on this reservation handler.
And the two things are we'll go back here and have a look at our page.
If we look at all reservations and you look at the world in the lower left hand corner of the screen,
we want to get that all to know what page were coming from, because there's two ways of getting to
the page we're working on right now.
We can get here from new reservations or we can get here from all reservations.
And we also need the ID in the form of an ENT so we can do our database query.
All right.
Well, none of that's too difficult.
So let's have a look and see how we're going to do it.
First of all, I'm going to grab the euro so right above this, because I'm not calling the database
yet.
I want to get the URL and I want to explode it, to split it.
And what I'm going to split it on are the slashes.
So I'll be able to find the individual parts of the user, you or I itself, for you or I or the URL,
whatever you want to call it.
So I'll create a variable called exploded and that's going to be equal to the value of from the strings
package.
The function split and split requires a few parameters.
First of all, what is the string you want to split?
What I can grab that from my request and it's our DOT request, you or I.
So that gives me the UI and then I want to split it on the slash.
So when this happens, see what the split returns.
It returns a slice of strings and we know how to find things from from a particular position in a slice.
The first position in a slice is zero.
The second one is one, the third one is two and so on and so forth.
So I've got my exploded variable.
What I can do now is, first of all, grab the ID, ID and potentially an error is equal to the value
of from the start convert package a two I were converting from alpha alphanumeric to or integer.
And what I want to convert is from the exploded slice of strings at position four and its position four,
because when I go back here and look at it, I'll inspect this so we can actually see it inspect the
element.
The actual you URL is zero for admin, one for reservations, two for all and three for split for slice.
Here I am lying to you.
We actually want it from one, two, three, position four.
It's the fourth position in the slice.
We're not counting from zero here at least apparently we're not.
We're about to find out.
Let's just try first of all, looking for there.
If error is not equal to nil, then I will just go helper's dot server error with my response writer
and the error and I'll return.
Not equal to nil, otherwise, let's just print out the ID, log print line ID.
OK, I'm going to stop my application and run because I'm not sure whether you count from slices that
position zero or position one.
And this will tell me.
So I'm going to run this.
Hit enter a few times just to get some blank spaces and then I'll click on one of these and see what
happens, and it gave me five and that's exactly what it should be, because it's five up here in the
URL.
OK, so it's right.
You don't count from position zero in slices, you count from position one, apparently.
No, you know, I'm not I'm not wrong.
Let me go back and look at this again.
It's amazing how quickly you forget things and they go to all reservations or new reservations and inspect
this element recounting by slices.
One, two, three, four, and everything on this side of the slice is the HDTV part, so that's exactly
right.
OK, I thought I was forgetting some basic information about go, but apparently I wasn't.
I'm just having a rough day and clearly require more caffeine.
Now, the next thing I want to get is actually that source variable, which I will use, but not right
now.
So I'm going to say source is a sign the value of from my exploded slice at position three, the one
just before ID, and that will tell me where I'm getting this information.
Now, what am I going to do with that?
I'm going to stick it in my string map.
So let's create a string map.
String map is assign the value of make a map, string, string and string map source as our key is going
to be equal to source.
And I'll stick that in my string map down here.
There now I also want some place I need to now to grab from the database the ID of the given reservation.
So here is where we use that database routinely, just create it.
So I'll call it resource error are assigned the value of my DB dot, get reservation by ID with the
ID I just pulled from the URL up here.
Check for an error and I'll just copy and paste this.
And now I want to have someplace to hold that information so I can pass it to my template, so as we
always do, we'll just create a map.
Data is a sign the value of make a map string.
Interface and data, and I'll call it reservation, because that's what it is.
Is equal to raise, and then I pass that to my template data data.
OK, so let's go back to our women's reservation page and see if we have this information.
And what I'll do here is right in the content.
I will say define a variable rez.
And that's a sign the value of from my data map of string interface index, DOT data reservation.
And here just to show that it's working, I'll put a printout resort first name and.
Reza, last name, and that should give me the information just to show that it works, so let's stop
our application, run our application.
Go back to our Web browser, close this this tab, reload the screen just to make sure everything is
current and I'll click on Jones and I get married.
Jones So there now I'm passing that necessary information to this screen.
So what I want to show here.
Well, I want to show some basic information at the top.
I want to show the guest name, the arrival date, the departure date and the room they're staying in.
And I don't want to have a form that allows me to modify information.
Well, we already have that form mostly built.
If we go back to the Make Reservation page, which is make reservation page two right here, I already
have this form, so I'm going to grab this form, the whole thing.
And I'll copy it and I'll go back to my admin reservation show page template and I'll just paste it
in here and make changes as necessary.
So instead of calling the input, make a reservation, I'll just call it save.
And then we'll go up to the top and we'll start making some changes.
So what's the very first thing that has to change?
Well, we're not going to the action of make reservation.
We're going to go to the action.
That's exactly the same as what we have right here at main reservation and either new or all and then
the ID.
So I'll change that.
Admin reservations.
And then I want to put the source here, so what I'm going to do is just after I grab the reservation
up here, I'll just create a variable SIRC, which is an index of string map.
And the thing I put it in, I believe, was SIRC.
That's the key.
I look it up.
So now I have this is a variable.
So here I can just go sirc and then what's the ID.
Well it's Rezo ID and there's an E in there and that should work.
Method is PPO's class is nothing.
No validate.
Perfect.
I need the CSIRAC token.
I don't care about this stuff so I'll get rid of those three hidden fields.
They don't matter at all.
And then we have first name.
First name that's all.
Correct.
Good.
But I notice that I'm using a form here.
So back in my handlers when I display this I had better pass it a form variable form forms dot new nil
so it'll actually render the page without an error.
So that's OK.
We have first name.
We have last name.
We have email.
We have phone.
And that's all the basic information.
OK, but I also want to add at this point a cancel button and the cancel should take me back to either
here new reservations, if that's where I came from or here, which is reservations all.
And you notice that the Uighurs are almost identical at the end of the all one.
We have Dasch all at the end of the new one, we have Dasch new.
So I can actually create a cancel out.
And just by saying a HSF equals and I'm going to go to admin reservations and then just put in my source
variable sorry, reservations dash and then my source variable, which is either new or all, and we'll
just make this look good.
Class equals button and I'll say button warning just to give it a different color and put cancel here
so that hopefully will work.
I think I have everything in here the way it should be.
OK, at the top here, I want to change the what's being displayed used to make this a little bit better.
So I'll say in a paragraph tag, cut that and paste it here.
And I already know their first name and last name because it's on the form.
So I'll say arrival and I'll make that in the strong arrival.
I'll try that again.
Strong arrival.
And that's going to be.
Reza, start date, but I wanted to look nice, so let's take advantage of that human date function.
We made a lecture or two ago and then on a new line, and I'll just duplicate this and change this to
end date and change this to departure.
And then we need the room.
So I'll duplicate that again and save room and change this to rez dorm room, dorm room name.
OK, there's too many EMS and admin, so let's fix that.
Perfect.
OK, let's see what we got wrong, so let's stop our application started our application.
And it's not populating any information in the form yet, but will be shortly.
Let's try clicking on it and see if we got it right.
Looks good.
It does look good and it's actually already put the information in the form.
Why did it do that?
Because I'm actually already using that same information here for er checking on the other other page.
So, hey, most of our work is already done.
Arrival is formatted properly.
Departure.
There's two columns in all of these.
Let's go fix that.
Don't need the colon's there.
Reload looks good.
The only thing that I don't like is that this admin template doesn't bould the labels for form tags,
so I kind of like that.
Let's go back and fix the labels.
Too many O's in room there.
So we'll go to our admin layout.
And right here I'll just redefine the tag label so it doesn't have a dot or a hashmark or anything in
front of it.
And I'll just say font weight bould save that reload.
That looks better.
OK, so we have this done.
The next step is, well there's actually a couple of steps left.
One is to make sure that this works.
Look at that admin reservation slash new.
I'm just full of typographical errors today.
So back here, find that cancel, get rid of the slash, reload this.
Let's make sure this works.
So we'll go to our reservation's new reservations.
When I click on this one, it should take me back to new reservations.
And it does.
And let's go to all reservations and click on this one.
And they should take me back to all reservations.
And it does.
So we're almost ready to go.
There's a couple of things left to do.
No.
One we want to means to mark this as processed.
Number two, we want a means to delete this entirely in case we don't want this reservation.
It was just something that we entered ourselves or was done in error, whatever we want, the ability
to delete it.
And finally, we want the ability to modify this information, to update the reservation, to change
the email address or change the phone or whatever it may be.
And none of that is difficult.
And we'll take care of that in the next lecture or two.