WEBVTT 00:01.710 --> 00:04.410 So let's try creating an invoice and see how it looks. 00:04.470 --> 00:06.000 So here is an invoice. 00:06.000 --> 00:09.960 Dash handlers don't go in the function creating an invoice. 00:10.500 --> 00:14.010 What I'm going to do, first of all, is a call to that function we just created. 00:14.040 --> 00:19.980 So we'll say error, assign the value of DOT, create invoice PDF in hand in order. 00:20.700 --> 00:30.540 Now, obviously, at this point, I'll see if error is not equal to nil after bad request w are an error 00:30.570 --> 00:31.410 and return 00:34.170 --> 00:37.220 and this has to be not an assignment variable. 00:37.230 --> 00:37.710 That's better. 00:37.950 --> 00:46.770 OK, so what we'll do up here is comment this out and then of course read that code and we'll just manually 00:46.770 --> 00:47.850 populate the invoice. 00:47.850 --> 00:56.640 So order ID is equal to say one hundred order email is equal to me here. 00:56.640 --> 01:00.690 Dot com order dot first name is equal to John 01:05.250 --> 01:05.610 Porter. 01:05.820 --> 01:08.430 Last name is equal to Smith. 01:08.790 --> 01:10.500 Not terribly original but there you go. 01:11.280 --> 01:16.260 And order dot quantity is equal to one order. 01:16.260 --> 01:21.480 The amount is equal to one thousand cents which is ten dollars. 01:22.770 --> 01:26.160 Order dot product is equal to widget 01:30.990 --> 01:32.370 and order created. 01:32.370 --> 01:37.290 That is equal to just time dot now just enough to make sure this is actually going to work. 01:37.680 --> 01:42.630 OK, so we have one, two, three, four, five, six, seven, eight. 01:42.870 --> 01:44.370 And just make sure we have everything. 01:44.370 --> 01:47.610 One, two, three, four, five, six, seven, eight. 01:47.610 --> 01:48.090 Perfect. 01:48.810 --> 01:51.660 So let's start our back into our starter micro service. 01:52.230 --> 01:53.940 Make start invoice. 01:56.550 --> 01:58.470 And now I should be able to go to my Web browser. 01:59.380 --> 02:06.280 And hit this URL, which I'll copy right now to make sure I get it right and it's under invoice route's 02:07.300 --> 02:08.200 copy this. 02:11.340 --> 02:21.690 I'll go to my Web browser and I'll go to the localhost port five thousand and paste in that you are. 02:24.080 --> 02:30.320 And there we have no error, so I should have a folder called invoices at the root level of my application 02:30.560 --> 02:34.210 and that should contain one file, one hundred PDF. 02:34.490 --> 02:35.200 Let's go have a look. 02:36.760 --> 02:42.610 So I have a folder called Invoices, and there's a file called one hundred point PDF, so let's go look 02:42.610 --> 02:44.620 at that file over here. 02:44.800 --> 02:45.700 There it is. 02:45.730 --> 02:47.220 One hundred PDF. 02:47.680 --> 02:48.250 Let's open it. 02:49.800 --> 02:56.820 And I have Bill to attention John Smith, me out here come the date the widget is here, quantity one 02:56.820 --> 02:58.070 and the total is ten dollars. 02:58.080 --> 03:01.030 And of course, you could fill the rest of this out yourself easily enough. 03:01.050 --> 03:03.070 I'm not going to do that because it's pretty simple to do. 03:04.050 --> 03:07.170 There's other things you could do here as well if you wanted to generalize it. 03:07.180 --> 03:14.250 So let's go back and look at the code again over here and bring up invoice handlers. 03:14.850 --> 03:18.070 Naturally, your invoice might have more than one thing. 03:18.420 --> 03:23.400 So at that point, what I would do instead of having one entry for product, one injury for amount, 03:23.700 --> 03:30.160 is I would put something like this items, and that would be a slice of a type that I defined, say, 03:30.180 --> 03:34.560 a slice of products, and I'd give it some JSON value. 03:34.570 --> 03:35.640 I'm not going to bother doing that. 03:35.640 --> 03:42.790 And then I define products like this type products struct and put everything in there. 03:42.800 --> 03:52.860 So product name so I can call just name, which would be a string and amount would be the price per 03:52.860 --> 03:54.060 item and that would be an end. 03:54.060 --> 03:55.290 So that's a price per item. 03:55.920 --> 04:02.100 And then I'd have quantity and that would be again and, and whatever else you want for per product 04:02.100 --> 04:02.640 sales. 04:02.640 --> 04:06.030 And then of course I would get rid of these three altogether. 04:06.120 --> 04:07.740 I'm not going to because I want this to work. 04:08.250 --> 04:13.980 And instead of passing just one item per request, I pass a slice of products and give it the appropriate 04:13.980 --> 04:19.380 Jason name over here, then down when I'm printing my invoice way down here. 04:21.060 --> 04:26.400 Instead of doing this once, I would put a range statement here, I would range through the slice of 04:26.400 --> 04:31.310 products and print one line at a time, and that's all I would really have to do, pretty straightforward. 04:31.770 --> 04:37.040 So everything from here to here would be inside the range, and that's pretty easy. 04:37.050 --> 04:40.800 And I'm going to undo everything I just did because I need to save this code and put it back up there 04:40.800 --> 04:41.210 for you. 04:41.610 --> 04:49.980 But clearly this does what it's supposed to, so I'll get rid of this and get rid of this and we're 04:49.980 --> 04:53.080 back to functional code, and that's a good start. 04:53.250 --> 05:02.940 So we actually now want to comment this about uncommented this get rid of this colon on the error statement, 05:02.940 --> 05:07.320 because there has been declared up here on line twenty seven and now we want to go back to our front 05:07.320 --> 05:10.620 end and actually call this micro service. 05:11.880 --> 05:14.340 But of course, before we do that, we have two more steps. 05:14.820 --> 05:19.200 Number one, creating an email and number two, sending the email with an attachment. 05:19.200 --> 05:20.980 And that is absolutely trivial. 05:21.000 --> 05:25.860 We'll take care of these two steps in the next lecture and then we'll actually call this micro service 05:25.860 --> 05:28.410 and make sure that it sends an email with an attachment.