1 00:00:01,620 --> 00:00:03,300 The order service is now all set up. 2 00:00:03,330 --> 00:00:07,150 So let's start to talk about the initial implementation we're going to work on in total. 3 00:00:07,170 --> 00:00:08,000 The order service. 4 00:00:08,010 --> 00:00:11,050 Like I said very similar in nature to ticketing. 5 00:00:11,130 --> 00:00:15,180 We're gonna have the list of root handlers you see right here all these right handlers are going to 6 00:00:15,180 --> 00:00:17,580 eventually be accessed from our front end react. 7 00:00:17,610 --> 00:00:21,680 Application in total we're getting four different root handlers. 8 00:00:21,680 --> 00:00:26,450 We're going to have one that's going to essentially serve as an index action and allow a user to get 9 00:00:26,450 --> 00:00:30,860 a list of all the orders that they have created over time. 10 00:00:30,860 --> 00:00:35,110 So in other words once the user starts to order tickets once they have purchased a couple I want to 11 00:00:35,190 --> 00:00:38,920 to list out all the different orders that the user is involved in. 12 00:00:39,140 --> 00:00:44,680 We're going to make sure that in order to access this route whoever is making the request they must 13 00:00:44,680 --> 00:00:49,930 be logged in or authenticated with our application because we're going to retrieve data for the current 14 00:00:49,930 --> 00:00:52,600 user. 15 00:00:52,610 --> 00:00:57,860 We're also going to make sure that we've got essentially the same thing but in a show kind of orientation. 16 00:00:57,860 --> 00:01:03,200 So if a user tries to make a request to API orders then the idea of an order we're going to return details 17 00:01:03,260 --> 00:01:04,730 about that order. 18 00:01:04,760 --> 00:01:09,080 Once again we're going to require a user to be authenticated to access this handler. 19 00:01:09,080 --> 00:01:13,970 We're also going to make sure that a user can only retrieve details about the order that they own. 20 00:01:13,970 --> 00:01:18,500 So in other words I'm not going to be allowed to access an order that was created by a different user 21 00:01:20,690 --> 00:01:22,760 will then have a right handler to create an order. 22 00:01:23,300 --> 00:01:28,040 So when we create an order we must provide the ticket I.D. or the idea the ticket that we are trying 23 00:01:28,040 --> 00:01:29,110 to purchase. 24 00:01:29,360 --> 00:01:33,980 That's going to create an order that's going to give the user some amount of time to then pay that order 25 00:01:34,160 --> 00:01:39,140 or provide their credit card details add in a payment to get their credit card charge and then only 26 00:01:39,140 --> 00:01:43,850 then will the user be in ownership of the ticket that they were trying to order. 27 00:01:44,050 --> 00:01:48,250 And then finally we are going to allow a user to cancel in order as well. 28 00:01:48,250 --> 00:01:52,900 So we will have a delete end point that allow the user to just cancel the order say I don't want to 29 00:01:52,900 --> 00:01:53,720 pay for this thing. 30 00:01:53,830 --> 00:01:58,390 Don't give it to me that's what I'm doing in total. 31 00:01:58,390 --> 00:02:03,770 So all that minus let's go create some root files we're gonna put some scaffold code together just to 32 00:02:03,770 --> 00:02:05,840 implement these different routes inside of each of them. 33 00:02:05,960 --> 00:02:11,790 We'll start to work on the implementation shortly after that so inside my orders directory I'm gonna 34 00:02:11,790 --> 00:02:13,710 make a new folder called Roots. 35 00:02:13,710 --> 00:02:18,750 Once again we're going to make some files inside of here that look very similar nature to the ones we 36 00:02:18,750 --> 00:02:20,690 have created back inside of tickets. 37 00:02:20,880 --> 00:02:24,920 So we're going to have very similarly named index new show. 38 00:02:25,020 --> 00:02:29,160 And then instead of update we will call it delete because we're not going to have the ability to update 39 00:02:29,160 --> 00:02:35,280 in order we will only have the ability to delete in order so inside of my new roots directory right 40 00:02:35,280 --> 00:02:45,620 here I'll make a index not to yes a new dot yes show and delete 41 00:02:49,750 --> 00:02:55,030 then inside the index yes file that we just create it we're gonna write out a little bit of sample code 42 00:02:55,030 --> 00:02:59,830 just to create a root handler with the appropriate method on it and the appropriate route and we'll 43 00:02:59,830 --> 00:03:04,560 copy paste that over to all these different root handlers and then wipe them all up inside the app yes 44 00:03:04,570 --> 00:03:09,340 file just to get the current import statement errors to go away and after that we should be able to 45 00:03:09,340 --> 00:03:13,600 successfully run this project inside of our communities cluster without getting any errors. 46 00:03:13,830 --> 00:03:22,200 So inside of index yes at the very top let's get express request and response from express 47 00:03:25,600 --> 00:03:32,030 well then wire that up with a router so express dot router. 48 00:03:32,190 --> 00:03:33,400 Now we're inside of index. 49 00:03:33,420 --> 00:03:33,710 Yes. 50 00:03:33,720 --> 00:03:38,970 Which means we want to have a get request handler that's watching for requests on API slash orders. 51 00:03:39,150 --> 00:03:47,310 So I can say router Duckett API orders and then inside of here I'll put in our actual account handling 52 00:03:47,310 --> 00:03:51,780 function going to market as a sync because we're probably going to have to do some async await stuff 53 00:03:51,780 --> 00:03:59,000 inside of here I'll then put in a request annotated as request rez entity as response. 54 00:03:59,020 --> 00:04:05,890 And right now I'll just do a resource send and I'll send back about empty object. 55 00:04:06,120 --> 00:04:13,030 And then finally I will export router as index order router. 56 00:04:13,280 --> 00:04:17,030 I think we might have use some slightly different terminology back inside of our tickets project or 57 00:04:17,060 --> 00:04:19,560 different semantics on the name of the router. 58 00:04:19,610 --> 00:04:20,920 No I guess we use the exact same. 59 00:04:20,950 --> 00:04:21,230 OK. 60 00:04:21,260 --> 00:04:24,640 That works yes that's good enough right now. 61 00:04:24,670 --> 00:04:29,790 So we're going to copy everything inside this indexed yes file and then I'm going to go round and paste 62 00:04:29,790 --> 00:04:34,710 it to the other three files on an after pasting it we will go into each of the three files and update 63 00:04:34,710 --> 00:04:43,670 the method and the root so here's new or semi delete yes inside of our order source roots directory 64 00:04:44,030 --> 00:04:54,470 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 65 00:04:54,770 --> 00:05:02,080 new and show so let's go through and update the method and the root for each of these I'll first start 66 00:05:02,080 --> 00:05:09,810 off inside of delete so here's delete T.S. will change the method right there instead of yet it will 67 00:05:09,810 --> 00:05:15,280 be a delete and as we just on this diagram we want to specify the idea of the order that we're going 68 00:05:15,280 --> 00:05:22,220 to try to delete so I'm going to replace the root right here with API orders and then order I.D. the 69 00:05:22,240 --> 00:05:26,680 diagram said we are going to have just I.D. We're going to call this thing order I.D. let inside of 70 00:05:26,680 --> 00:05:31,750 the actual root handler we access it as a parameter called Order I.D. just makes our code a little bit 71 00:05:31,840 --> 00:05:39,070 easier to understand after that I will save the delete s file and close it up one more thing let's make 72 00:05:39,070 --> 00:05:45,850 sure we update that name at the very bottom so I'll change this to delete order router that's better 73 00:05:47,530 --> 00:05:50,820 next up let's take care of show so insiders show us. 74 00:05:51,310 --> 00:05:57,910 We want to make sure we can make a get request to API orders than the order I.D. so get to API orders 75 00:05:59,610 --> 00:06:08,800 all in order i.e. and then we will update that index right there to show instead I will say this and 76 00:06:08,800 --> 00:06:16,240 close it then finally for new we want to be able to make a post request to API orders so inside of new 77 00:06:16,260 --> 00:06:27,960 tests we'll do post to API orders and then I'll change the router name on here as well to new order 78 00:06:28,020 --> 00:06:31,570 router now that we've made all these updates. 79 00:06:31,570 --> 00:06:36,070 We're gonna go back over to our app TSA file and fix up all the import statements inside there. 80 00:06:36,100 --> 00:06:38,850 So inside my order service I will find apt. 81 00:06:38,860 --> 00:06:43,750 Yes we've got these import statements that we're just really copy pasted over from all the ticketing 82 00:06:43,750 --> 00:06:44,620 stuff. 83 00:06:44,620 --> 00:06:49,680 So we're going to delete all for these and then replace them with for imports for the routes we just 84 00:06:49,680 --> 00:06:50,700 created. 85 00:06:50,700 --> 00:07:00,090 So we will do an import delete order router from roots delete. 86 00:07:00,340 --> 00:07:06,720 I'm going to then take that import and paste it down three times and then we'll just go through each 87 00:07:06,720 --> 00:07:08,280 of these and update the names. 88 00:07:08,700 --> 00:07:17,790 So for the next one we'll get the index so we'll change it to index or the router from roots slash index. 89 00:07:17,800 --> 00:07:20,290 Next up we'll take care of new. 90 00:07:20,350 --> 00:07:25,440 So new order router from roots slash new. 91 00:07:25,490 --> 00:07:26,600 And then finally show. 92 00:07:26,630 --> 00:07:35,340 So we'll update this to show what a router from roots slash show. 93 00:07:35,420 --> 00:07:42,360 And then finally the why are these up to our Express application going to copy paste these four router 94 00:07:42,360 --> 00:07:42,780 names 95 00:07:46,480 --> 00:07:50,870 all then go down to where we've got the other or routers that we have previously wired up inside of 96 00:07:50,870 --> 00:07:55,610 here inside of our ticket service and delete all those I'm gonna write in the four outer names that 97 00:07:55,610 --> 00:08:00,950 we just put together and then I'll wrap each of those in an apt use call. 98 00:08:00,960 --> 00:08:06,480 You'll notice I'm doing some multi select magic here essentially all we need to do is end up with exactly 99 00:08:06,480 --> 00:08:06,960 this. 100 00:08:06,960 --> 00:08:08,150 That's it. 101 00:08:08,220 --> 00:08:17,780 So app use for delete index new and show and that should be at once we've got that put together we should 102 00:08:17,780 --> 00:08:23,250 have no more ears inside this file so I don't see any errors inside of here whatsoever. 103 00:08:23,310 --> 00:08:29,140 I'm going to save Apple yes I'm then going to check for errors inside of index to us and Nat's wrapper 104 00:08:29,450 --> 00:08:33,580 to make sure I don't have any typescript related errors inside my project because at this point I really 105 00:08:33,580 --> 00:08:36,380 do expect this to successfully run in my terminal. 106 00:08:36,700 --> 00:08:37,700 So I can go to index. 107 00:08:37,820 --> 00:08:39,040 Yes. 108 00:08:39,250 --> 00:08:40,660 I don't see anything wrong inside of here. 109 00:08:40,660 --> 00:08:42,130 Everything looks good to me. 110 00:08:42,550 --> 00:08:44,030 And that's wrapper. 111 00:08:44,140 --> 00:08:45,430 No errors inside of here. 112 00:08:45,430 --> 00:08:46,840 Everything looks good to me as well. 113 00:08:48,850 --> 00:08:51,570 So I got to make sure all those files are saved. 114 00:08:51,570 --> 00:08:55,950 I should then be able to go back over my scaffold window and see connected to that's connected Mongo 115 00:08:55,950 --> 00:09:02,360 beat DV and listening on port three thousand if you do not see this if you just see some more errors 116 00:09:02,390 --> 00:09:06,230 or if you just see all these same kind of watching for changes stuff. 117 00:09:06,230 --> 00:09:12,800 Then again remember you can close out scaffold you might try rebuilding our image so rebuild the order's 118 00:09:12,800 --> 00:09:18,440 image entirely by doing a docker build inside the orders project directory and then start scaffold backup 119 00:09:20,270 --> 00:09:23,870 and the ultimate goal here is to make sure that we see orders saying that's connected to and that's 120 00:09:23,870 --> 00:09:26,340 Mongo DV and listening on port three thousand. 121 00:09:26,570 --> 00:09:30,830 And naturally if you run into any issues that you just can't get this thing working you can always take 122 00:09:30,830 --> 00:09:35,030 a look at my source code that is attached to this video inside a zip file. 123 00:09:35,030 --> 00:09:40,220 Just remember if you download my zip file you probably are going to want to update all the package Jason 124 00:09:40,220 --> 00:09:47,770 files from using my common library to whatever your com library is instead. 125 00:09:47,790 --> 00:09:49,670 So we've got our order service and a pretty good spot. 126 00:09:49,680 --> 00:09:53,480 It is up and running which means we can now start to work on these different root handlers. 127 00:09:53,490 --> 00:09:55,220 Let's get started on that in just a moment.