So in the last lecture, we identified one problem, and it's actually three problems, but the first
one, the one we identified was here.
When I'm on the reservation calendar, if I go to a reservation, not a booking or a block or whatever,
but I go to an actual reservation or an actual booking and I try to market has processed, it will take
me to a page not found.
And that's because it's taking us to a route that doesn't exist.
If you look in the reservations handler over here and we find the post reservation when we do our redirect
at the bottom, we're always going to it's admin's reservations, Dasch, something SIRC and the Sarsae
is actually grabbed from this part of the URL and there is no path.
Admin's reservations.
Dasch count now an easy fix and not a good one, but an easy fix would be to set up a new route that
matches admin's reservations.
Dougall and it always takes the user back to here.
And the only problem with that, of course, is it's great if I'm doing a reservation for the current
month, but if I go to a different month and click on this and then click Save or Marquez processed
and this one happens to be processed, but if I clicked on the Marquez processed button, it would actually
take me back to the current month and year in the calendar, which isn't where I came from.
And that's nonintuitive.
And that's going to cause some grief for the actual user of the application.
So that's not a great idea.
What might be a better idea is to pass, say, some query parameters.
So questionmark Y equals twenty twenty or twenty, twenty one and month equals twenty or 02 and that
would take me to February of twenty twenty one.
So that would mean that I would have to pass this early, grab the query parameters, put them in hidden
fields in here and away we go.
There's only one problem with this, and that is the way that we're getting this I.D., that nine in
this case.
So if we go back and look at the way that we're doing it on the admin show, reservation page, which
is right here, we're actually getting the ID by exploding or splitting our request, you or I.
And that's this entire U.
URL up here.
We're splitting that on the slash and we're getting the item in the fourth position as the ID and then
converting that to an end.
OK, so right now we have this is position zero.
Admin is position one reservation a position to Kala's position three.
And now all of this is position four.
And I can't split that or can't convert that string to an end because clearly it's not it it's got letters
and punctuation in there.
So I need somehow to deal with this problem.
How am I going to get both the ID and the year and the month?
And I want the year in a month so I can redirect them back to the appropriate month on the calendar?
Well, there's a couple of ways of doing this.
We could first of all, one option is to change that.
Nine, the ID from a part of the actual euro Eurail into it, another query parameter that would work
like that one.
But that would work or and this is a little complicated, but I could explode it as I am right now,
then take that exploded for and check to see if it contains a question mark.
If it does, then split exploded four on the question mark and grab position zero.
That will be the ID again.
Very awkward.
It might be simpler if I just change the URL to something like this show and then year in month, because
now position four will always be an aunt.
I ignore position five and I still have access to my query parameters.
Let's do that.
So I'll go over to my roots file, which is right here, and I will change the bit where I'm showing
a reservation just by putting a slide show after it.
Now, of course, that means any changes in more places.
I need changes on the reservation calendar page, so let's find that and put its slash.
There are slash show right here at the very end and that's all I have to do.
We also need it for this page, new reservations and for this page, all reservations.
And we might have to do some redirects, but we'll check those out in a minute.
So let's go to new reservations.
And all I have to do is say show after the URL bit and all reservations and put a show here as well.
OK, let's stop our application just in case.
Start it up again.
It compiles let's make sure all of that works.
So let's go to the dashboard just to make sure we're on a new page, go to new reservations.
OK, that worked.
Let's go to all reservations.
That worked.
Let's go to the reservation calendar.
And that worked perfect.
Now, this last one where I came from, the reservation calendar, here's where I want the questionmark
y equals the year and then so on and so forth, the month.
So let's go back to our admin reservations calendar page and just add those to the URL.
So I'll make this a little wider.
And all I have to do is questionmark y equals Curre year.
Ampersands.
M equals per month because I already have current year and current month stored in variables, so I
don't need to pull them out of the stream out there, right here so I can save this.
Go back here.
Let's go back to the reservation calendar.
I shouldn't have to restart because I'm reloading the templates on every request.
The euro looks right in the lower left.
Let's see if it works.
And it does.
So now I have the year in the month, so I better put them as hidden fields on this actual page so I
can do something with them.
So let's go to the reservation show page or reservation handlers find that first we want to show the
reservation and all I need to do is to grab the year in the month from the query parameters.
So I'll do it after I declare the string maps so I can add them right to the string map.
And I'll say here is a sign the value of our euro dot query doget and I'm looking for Y and then I'll
duplicate this and I'll put month is equal to M and now add those to our string map string map month.
Equals month and do the same thing for a year.
OK, and then on the admin reservation show page, now that I have those, once I restart my application,
I'll have them.
Now I can put them in here, sit hidden fields.
The input type equals hidden name equals year value equals index dot string map here.
And close that and duplicate this and make that a month.
And make this month and stop our application and start our application.
And we'll go right back to the calendar page just to make sure everything's working properly, and this
time I'll use December 20/20 and I'll try this reservation.
OK, there's my year in my month and let's check our source code and look for the word hidden.
And there's year in month.
Perfect.
OK, so I have those now.
So now I can finally at this point determine whether or not I have to do a redirect.
So let's go back to our handler and just look at this one more time.
So when I grab my year in one month from my query parameters.
If there is no query parameter, those should be empty strings, let's make sure that actually works.
So here's a way I'm going to get to a reservation with no query parameters, no month and year.
So this should still show it.
And now when I view the source and look for hidden, they should be empty and they are perfect.
So this will definitely work.
So now that I have those things posted or available to my post, they're coming to this handler admin
post show reservation.
Let's just go back to the calendar and get to one.
Those two values, year and month are now part of the post request that matches this handler.
So when I come all the way down here, all I have to do is to see if I have a month and a year value
that are not empty strings and I can just grab them right from the request.
So a month is assigned the value of our not formed get em and then year.
Is why I just have to make a determination here and I'll do it after I write to the sessions, I don't
want to bother duplicating that.
If a year is equal to nothing, an empty string, then just do what we've been doing right along.
Otherwise, we'll redirect somewhere else.
And we're we're going to take them is to the calendar page, but the correct month and year.
So reservations dash calendar.
Questionmark Y equals, and then a string ampersand M equals and then another string, and now I don't
care about the source, I care about year and month.
So in theory, this should work.
Let's find out and if it works for here, we can use the same logic for processing a reservation and
deleting a reservation.
So we're running.
Let's go back here and go to our reservations calendar and bring up a reservation and save it.
Page not found.
What did I do wrong, maybe I didn't reload the page.
Let's look at this, make sure that we have our month in year, year and month 2020 and 12 admin reservations
calendar.
And where are we doing our redirect process reservation?
We want to admit we want the post reservation.
So if we're equals that are formed, I get em.
And why?
What did I call them in here?
Oh, you're in month.
That'll explain it.
Month and year.
I was looking for parameters that didn't exist.
So let's stop it and try it one more time.
So we'll close this, go back to Reservation's calendar, bring up general quarters reservation, save
this, and they should take me back to that year and that month, December twenty twenty.
And it does.
Let's try one in the future.
So here's one.
Let's save that one.
That should take me back to January of twenty twenty one.
And it does.
Now what about going the old way directly from, not from the calendar.
Let's bring up this pennyworth reservation that should take me back to reservations new because that's
what they have in my URL is new save and it takes me to reservations.
New perfect.
Well that seems to work.
So now we can do the same thing or use the same logic for making a reservation as processed.
So let's go back to our code and our terminal window and find the reservation show page.
So this is the part when I bring up a reservation this way, if I want to mark this is processed, what
is it actually doing?
Well, if you recall on this page showing a reservation at the very bottom, we have this process reservation
and that is calling the your admin process reservation, whatever the sources of the ID.
And now I need to actually pass some query parameters.
So how am I going to do that?
Well, let's go to look at this actual handler.
Let's find the roots.
Let's find the process reservation, which is right here, and bring that up.
So that's getting the URL the same way or getting the ID from the world the same way that we did in
the last one.
And it's using the key rooters, Eurail, Perram.
I suspect that that works pretty much the same way that we've been doing it by hand.
So what I'm going to do is actually change the route for deleting or deleting a reservation and for
processing a reservation.
So, again, I'll just put this something at the end of it.
And what I'll put here is processed reservation process, Dasch reservation, whatever the source is,
whatever the ID is, and then I'll just put a word here do and that'll do it for our purposes.
So let's go back to the admin reservation show page and change this URL to do.
And.
That would come after this, move this down here.
Plus, do you do?
Questionmark and then Y equals I'll pass my year, my month in the same way I have been in the other
one, that would be index dot, string map.
Year ampersand.
M equals index dot string map.
And that should work.
So let's just see if that is rendering the way that I expect it to render.
So I start and stop, stop and start my application and I'll go back and I'll just reload this page.
OK, that's shut up.
All right.
And let's go to the very bottom.
So we're going to have admin process, Dasch reservation slash cow slash, then the idiot slash du questionmark.
That looks perfect.
All right.
So since we're here anyway, let's use the same logic.
Copy this.
Let's just update our you, Earl, for this one as well.
And save that and reload this and I should see the same thing showing up right here.
If I can get down to the bottom of the page.
Yes.
All right, so that means we need to update our route for deleting just by putting a slash do after
it, I just chose to do because I'm doing something.
It's an action.
And then we need to do the same logic in admin process reservation.
So I now have my ID.
I don't need to worry about that at all.
I now have my source.
I don't need to worry about that at all.
And I can also now just check for the year and the month and this time they're showing us query parameters.
So yea is a sign the value of our euro query dot get and I'm looking for why duplicate that and month.
I'm looking for M.
And I'll leave my session alone, but here, I'll do a check if here is equal to nothing, in other
words, if there is no query parameter for that.
And take them back there where we were at along, otherwise take them to the correct month and year
in the calendar.
So a copy this, I'll paste it.
I'll change that to reservations calendar questionmark month equal or Y equals some string.
Make that an equal sign or this isn't going to work.
Ampersand month equals another string and I substitute year and month and I should work.
So let's try this, let's stop it and start it.
It compiles.
Let's go back to our reservations calendar and this should take me back to December of twenty twenty
once I market as processed.
And it does perfect, so now we just need to do the same thing for delete.
And one note here, just before I recorded this lecture, when I was running through things to make
sure they all worked, I noticed that my when I marked a reservation as processed, the button still
showed up.
So it's possible that I made that change between lectures.
It's equally possible that I made the change during a lecture.
But all you have to verify is on the admin dash reservations that show page template.
Just make sure that this part is here, that the if statement is still around, that Mark has process
button.
If it's not added back in, it's possible I deleted it inadvertently in a previous lecture.
It's also possible I deleted it between lectures.
But if you're still seeing that button after you mark something is processed, just make sure that this
if statement exists in your template.
All right.
So the last thing we have to do then is to make this delete button work the same way.
So I've already updated the route to put to do after it on the admin show reservations page.
I need to make sure that I have to do after this and I do OK.
So I now need to open up the admin, delete reservation and use the same logic we did above so I can
just copy this bit.
Getting my year in month from the query parameters, put them here and again just do the if a year is
equal to nothing or an empty string, take them where we have been right along.
Otherwise take them back to this path which I'll just copy and paste because I already have it and I
know that it works.
So if the error is empty, in other words, if there's no query parameter, why then take them back
to the place we have been right along.
Otherwise take them back to the correct year and once in the calendar.
So let's stop this.
Start this.
And now we need to make sure this works over the reservation calendar.
I'll go ahead a month just to make sure I'm looking at a different one.
And this time I'll delete whatever this reservation is on the 20th of January in the major suite.
So hopefully this'll work.
Yes, I'm sure.
And it works.
So there now we have the core functionality all working exactly as it should for our back end.
So the last thing we have to do is the next thing we have to do, not quite the last thing.
The next thing we have to do is to update some tests.
And I'm going to do one test for you and let you do the rest of them on your own.
I'll do a table driven test for some one of the handlers and I will complete the rest of them.
But I'm only going to do one is a lecture and the rest of them will just go up as the source code and
you can review them as you wish, because at this point you should be able to write these tests on your
own.
But in case you can't, I will provide the full source code for your review.