The order service is now all set up.
So let's start to talk about the initial implementation we're going to work on in total.
The order service.
Like I said very similar in nature to ticketing.
We're gonna have the list of root handlers you see right here all these right handlers are going to
eventually be accessed from our front end react.
Application in total we're getting four different root handlers.
We're going to have one that's going to essentially serve as an index action and allow a user to get
a list of all the orders that they have created over time.
So in other words once the user starts to order tickets once they have purchased a couple I want to
to list out all the different orders that the user is involved in.
We're going to make sure that in order to access this route whoever is making the request they must
be logged in or authenticated with our application because we're going to retrieve data for the current
user.
We're also going to make sure that we've got essentially the same thing but in a show kind of orientation.
So if a user tries to make a request to API orders then the idea of an order we're going to return details
about that order.
Once again we're going to require a user to be authenticated to access this handler.
We're also going to make sure that a user can only retrieve details about the order that they own.
So in other words I'm not going to be allowed to access an order that was created by a different user
will then have a right handler to create an order.
So when we create an order we must provide the ticket I.D. or the idea the ticket that we are trying
to purchase.
That's going to create an order that's going to give the user some amount of time to then pay that order
or provide their credit card details add in a payment to get their credit card charge and then only
then will the user be in ownership of the ticket that they were trying to order.
And then finally we are going to allow a user to cancel in order as well.
So we will have a delete end point that allow the user to just cancel the order say I don't want to
pay for this thing.
Don't give it to me that's what I'm doing in total.
So all that minus let's go create some root files we're gonna put some scaffold code together just to
implement these different routes inside of each of them.
We'll start to work on the implementation shortly after that so inside my orders directory I'm gonna
make a new folder called Roots.
Once again we're going to make some files inside of here that look very similar nature to the ones we
have created back inside of tickets.
So we're going to have very similarly named index new show.
And then instead of update we will call it delete because we're not going to have the ability to update
in order we will only have the ability to delete in order so inside of my new roots directory right
here I'll make a index not to yes a new dot yes show and delete
then inside the index yes file that we just create it we're gonna write out a little bit of sample code
just to create a root handler with the appropriate method on it and the appropriate route and we'll
copy paste that over to all these different root handlers and then wipe them all up inside the app yes
file just to get the current import statement errors to go away and after that we should be able to
successfully run this project inside of our communities cluster without getting any errors.
So inside of index yes at the very top let's get express request and response from express
well then wire that up with a router so express dot router.
Now we're inside of index.
Yes.
Which means we want to have a get request handler that's watching for requests on API slash orders.
So I can say router Duckett API orders and then inside of here I'll put in our actual account handling
function going to market as a sync because we're probably going to have to do some async await stuff
inside of here I'll then put in a request annotated as request rez entity as response.
And right now I'll just do a resource send and I'll send back about empty object.
And then finally I will export router as index order router.
I think we might have use some slightly different terminology back inside of our tickets project or
different semantics on the name of the router.
No I guess we use the exact same.
OK.
That works yes that's good enough right now.
So we're going to copy everything inside this indexed yes file and then I'm going to go round and paste
it to the other three files on an after pasting it we will go into each of the three files and update
the method and the root so here's new or semi delete yes inside of our order source roots directory
so I'll paste I will then find new to yes paste and show T.S. and paste so I should now have index delete
new and show so let's go through and update the method and the root for each of these I'll first start
off inside of delete so here's delete T.S. will change the method right there instead of yet it will
be a delete and as we just on this diagram we want to specify the idea of the order that we're going
to try to delete so I'm going to replace the root right here with API orders and then order I.D. the
diagram said we are going to have just I.D. We're going to call this thing order I.D. let inside of
the actual root handler we access it as a parameter called Order I.D. just makes our code a little bit
easier to understand after that I will save the delete s file and close it up one more thing let's make
sure we update that name at the very bottom so I'll change this to delete order router that's better
next up let's take care of show so insiders show us.
We want to make sure we can make a get request to API orders than the order I.D. so get to API orders
all in order i.e. and then we will update that index right there to show instead I will say this and
close it then finally for new we want to be able to make a post request to API orders so inside of new
tests we'll do post to API orders and then I'll change the router name on here as well to new order
router now that we've made all these updates.
We're gonna go back over to our app TSA file and fix up all the import statements inside there.
So inside my order service I will find apt.
Yes we've got these import statements that we're just really copy pasted over from all the ticketing
stuff.
So we're going to delete all for these and then replace them with for imports for the routes we just
created.
So we will do an import delete order router from roots delete.
I'm going to then take that import and paste it down three times and then we'll just go through each
of these and update the names.
So for the next one we'll get the index so we'll change it to index or the router from roots slash index.
Next up we'll take care of new.
So new order router from roots slash new.
And then finally show.
So we'll update this to show what a router from roots slash show.
And then finally the why are these up to our Express application going to copy paste these four router
names
all then go down to where we've got the other or routers that we have previously wired up inside of
here inside of our ticket service and delete all those I'm gonna write in the four outer names that
we just put together and then I'll wrap each of those in an apt use call.
You'll notice I'm doing some multi select magic here essentially all we need to do is end up with exactly
this.
That's it.
So app use for delete index new and show and that should be at once we've got that put together we should
have no more ears inside this file so I don't see any errors inside of here whatsoever.
I'm going to save Apple yes I'm then going to check for errors inside of index to us and Nat's wrapper
to make sure I don't have any typescript related errors inside my project because at this point I really
do expect this to successfully run in my terminal.
So I can go to index.
Yes.
I don't see anything wrong inside of here.
Everything looks good to me.
And that's wrapper.
No errors inside of here.
Everything looks good to me as well.
So I got to make sure all those files are saved.
I should then be able to go back over my scaffold window and see connected to that's connected Mongo
beat DV and listening on port three thousand if you do not see this if you just see some more errors
or if you just see all these same kind of watching for changes stuff.
Then again remember you can close out scaffold you might try rebuilding our image so rebuild the order's
image entirely by doing a docker build inside the orders project directory and then start scaffold backup
and the ultimate goal here is to make sure that we see orders saying that's connected to and that's
Mongo DV and listening on port three thousand.
And naturally if you run into any issues that you just can't get this thing working you can always take
a look at my source code that is attached to this video inside a zip file.
Just remember if you download my zip file you probably are going to want to update all the package Jason
files from using my common library to whatever your com library is instead.
So we've got our order service and a pretty good spot.
It is up and running which means we can now start to work on these different root handlers.
Let's get started on that in just a moment.