So we have our database function, and the next step is to set up a root and a handler on the API so
we can use that function.
And that's pretty straightforward.
So I'm looking at Route's Dash API Dutko and in this section on line thirty two in my code, I'll add
a route that is protected for admin users only.
I don't make a post route.
It could be a cat, but I'm going to make it a post and I'll just call API admin, which we get from
line thirty two and then all the sales, which could be all orders.
But I'm going to go with sales and I'll call a handler that doesn't exist yet called at all sales and
I will go create that handler some over two handlers API and I'll put it at the very bottom of this
function or this file and I'll create a funk with the receiver of the application and I'll call it all
sales and it's a handler.
So we'll give it its response rate and it's a pointer to a request.
And this is dead simple.
All we do here is, say, all sales, which is a variable I'm declaring right here and potentially an
error come from after DB get all orders with no parameters.
Check for an error.
If error is not equal to nil.
All I'll do right now is just say after that request and that requires w are in the error return.
But if we get past that point then we can send JSON back, which is a simple now as going right Jason.
And handing it W status.
OK, or whatever status you choose to use and the variable or sales and that should be it.
So now we should be able to go and write some JavaScript on the front end to call this handler, which
gets all the sales and returns and was chosen, and we'll get started on that in the next election.