So this time around, we want to start working on this sort of thing, if I go to all sales after logging
and I want this link to work and as you can see, if you can inspect it, it's inspected here.
The URL for that is slash admin, slash sales, slash whatever the order it is.
So we want to actually have that page display because right now, if I click on it, I get a page not
found here and that's no good.
So let's go back to our code, and the first thing I'll do is go to my roots, go.
And in this part where I have everything protected admin, let's just add a root right in here so mux
don't get and it will be slash admin, which I get automatically from the root handler or function slash
sales and then some I.D. and the router wants us to put that in curly brackets like that.
And then I'll point to a handler that doesn't exist after show sale and let's go create them.
So if I go to my handlers, handlers don't go inside the web folder and at the very bottom, I'll create
a handler for slash sales, slash some IDE called show sale.
And it's basically the same as this one, so I can just copy and paste it and change it to show sale
and I'll render a template that doesn't exist yet, which I'll call.
So that means I need to go over to my templates folder and create a new file called Sayle Page Dot Go
HTML.
And we'll put a really simple one here to start with, template will be based and we're going to possibly
hand data to this.
We are handing needed to it and we'll define the title, which is Just Sale
and close that.
And I will define the content area
and I'll put it there right now is just age two class equals empty dash five sale and close to put it
in there and we'll populate this with more stuff later on.
So let's end that.
And this is going to have JavaScript as well.
So let's put in our section for JavaScript defined Gio's and we'll just leave it empty for the moment.
So we have a handler, we have a route and we have a template.
So this will actually work if we run it.
Let's verify that.
So I'll open my terminal.
Next up, make start.
And let's see if we get everything right, just to make sure it's all hooked up properly by clicking
on Order three in my case and you click on whatever order you have, and there it is.
OK, now let's go back and work on some JavaScript for this.
And what I'm going to do to save some time is open the all subscriptions or all sales page and just
copy the entire content of this JavaScript and we'll modify it because it'll be very similar to what
we need to do right now.
And back to Sale Page and I'll just paste the JavaScript in there.
All right.
There are going to be some changes.
The first thing is if I go back and look at this, I need to get the ID from the URL right here.
So it's admin slash, sales slash and then the order ID and I need to get that from the URL.
Unfortunately, JavaScript makes that pretty easy.
So I'll get rid of this Tebaldi because I'm not going to use that.
I'll leave that alone and I'll have this U.
URL will make it back in early.
That goes to get Dasch sale and then it will be a slash and then plus whatever the ideas, we don't
have that yet.
So let's get it up here after I get my token, which I know I'm going to need, let's just put let iid
equal window location, dot pathing dot split and I'm going to split on the slash and I want to pop
it to get the last one and that should get me the ID.
So let's just console, get rid of this stuff and get rid of all of this stuff.
Right here, the entire if statement in the last where clause, and I'll just comment about this right
now so we can actually run this.
So let me stop my application, make it stop, make a start, and I'll just start the back end.
And then I'll run air, so if I need to make changes, I don't have to start and stop things all the
time.
So let's go back here and.
Open the terminal and make sure it all renders without a JavaScript error, so we'll go to the console,
clear it and reload this.
OK, no air except no Fabi confound and that I don't care about, so let's make sure we actually get
the ID.
So what I'll do here is say console log
ID is Colma ID and save that.
Let er rebuild it.
And go back and reload that page my browser and make sure I get the ID from the URL and IDs three.
That's exactly what I wanted.
OK, so let's go back now and fix up this statement and then we'll go right.
The necessary stuff in the backend.
So I'll uncommented this.
And get rid of that console log.
They don't care about that, so I'm going to call API slash, API slash admin slash and get sale and
an I.D. And what I want to do at that point is just say console that log data so we can see what data
we get.
So the next step is to go create a route for API slash admin slash, get sales some ID in our API.
So let's go to the Roots Dash API folder or file and we'll just do this really quickly.
So we'll create a new route in our protected section.
In my case that starts on line thirty two.
We'll just put one in here so it'll be a post Muxtape post and we get slash API slash admin from the
Muxtape route and then we want slash and get dash sales some.
So I put that in curly brackets because I'm using the key router and I'll call a handler app.
Don't get sale.
That doesn't exist yet, but we're going to make it right now.
So let's go to Handler's API Handler's Dash API Dutko.
And at the very bottom of this, you can put it wherever you want, but I'm going to put it at the bottom.
Can you handle it and I'll just copy this one to say some time and paste it in here and I'm going to
call it and get Sayle.
So I'm not going to get all sales from the database, instead I'm going to get one sale from the database.
So let me just clear all this out and I'll leave the right.
James will be using it shortly and I'll say I need to get the ID and we use the key utility function
for that chheda Eurail Perram.
And we're looking for from the request we're looking for ID, lower case ID and I need to convert that
to an end.
So order ID is that's what it is.
And I'm going to ignore the error.
You shouldn't put an error check in there.
Sturckow toward.
And I'm going to look for I.D., so I convert it into order, I.D. in it, and that's what I'm going
to need in a minute because I'm going to look for an order, potentially an error, and I'll call a
database function that doesn't exist yet at DV Dot and I will call it Get Order by ID and I'm going
to pass it already and I will check for an error.
If error is not equal to nil, then I'll just say after that, request it again and request and hand
it over and the error and I'll return.
Otherwise I'm going to write the Jason Porter.
Now obviously this won't work yet because get order by ID doesn't exist.
So let's go to models.
Don't go the very bottom of this file.
And if you think about it, getting one order is virtually identical to this function.
Get all subscriptions or get all sales.
So what I'll do, we're just going instead of getting all of them, we're going to get one by ID.
So I'll copy this and paste it right here and scroll back up and rename it to get order by ID.
And it's going to return one order, not a slice of pointer store orders and potentially an error.
So we'll create our variable, which I'll call.
Oh, and you'll see why in a minute just to say some work of type order.
This is our query.
But we don't want where this equals one.
We want where oh ID equals questionmark and this is going to change to a singular row is equal to imdb
dot query row context and we're going to hand it the context and we're going to hand it ID and this
is query row contents, which is why I have an error, the error there and we're going to take the ID
as a parameter up here.
Idee is a type int.
OK, so now we have a row and we don't check for an error like this, or do the rows close because we
don't have rows anymore.
Instead we scan the row like this and we get rid of this.
And this is why I went with O for my variable name up here on line four fifty seven.
So I don't want to change all of these old to order.
OK, I may be a little lazy so we check for that and then down here we can get rid of these two things.
And will return, oh, and the air will return oh, here and we have one more mistake, and that error
needs to be an assignment operator.
So that should fix it.
So now if I say this, it should formatted no error.
Show up.
I can go back to Handler's API, no errors here and I can go back to reach API.
No errors.
So I should be able to stop this make stop make start to get everything running.
And go back to my Web browser, make sure the console is open, and now when I reload this, I should
get some Jason back.
And I do.
So let's go to the network tab.
Look at the post request and look at the response and there's my order, and if I switch it to raw as
you can and in Firefox, there's all the information I'm probably going to need.
So at this point, I've managed to successfully call the back end pass at the ID that I've grabbed from
the URL and get the response as Jason.
And all that we have to do now is take the information out of our Jason file and write it to the screen
and we'll take care of that in the next election.