So let's try creating an invoice and see how it looks.
So here is an invoice.
Dash handlers don't go in the function creating an invoice.
What I'm going to do, first of all, is a call to that function we just created.
So we'll say error, assign the value of DOT, create invoice PDF in hand in order.
Now, obviously, at this point, I'll see if error is not equal to nil after bad request w are an error
and return
and this has to be not an assignment variable.
That's better.
OK, so what we'll do up here is comment this out and then of course read that code and we'll just manually
populate the invoice.
So order ID is equal to say one hundred order email is equal to me here.
Dot com order dot first name is equal to John
Porter.
Last name is equal to Smith.
Not terribly original but there you go.
And order dot quantity is equal to one order.
The amount is equal to one thousand cents which is ten dollars.
Order dot product is equal to widget
and order created.
That is equal to just time dot now just enough to make sure this is actually going to work.
OK, so we have one, two, three, four, five, six, seven, eight.
And just make sure we have everything.
One, two, three, four, five, six, seven, eight.
Perfect.
So let's start our back into our starter micro service.
Make start invoice.
And now I should be able to go to my Web browser.
And hit this URL, which I'll copy right now to make sure I get it right and it's under invoice route's
copy this.
I'll go to my Web browser and I'll go to the localhost port five thousand and paste in that you are.
And there we have no error, so I should have a folder called invoices at the root level of my application
and that should contain one file, one hundred PDF.
Let's go have a look.
So I have a folder called Invoices, and there's a file called one hundred point PDF, so let's go look
at that file over here.
There it is.
One hundred PDF.
Let's open it.
And I have Bill to attention John Smith, me out here come the date the widget is here, quantity one
and the total is ten dollars.
And of course, you could fill the rest of this out yourself easily enough.
I'm not going to do that because it's pretty simple to do.
There's other things you could do here as well if you wanted to generalize it.
So let's go back and look at the code again over here and bring up invoice handlers.
Naturally, your invoice might have more than one thing.
So at that point, what I would do instead of having one entry for product, one injury for amount,
is I would put something like this items, and that would be a slice of a type that I defined, say,
a slice of products, and I'd give it some JSON value.
I'm not going to bother doing that.
And then I define products like this type products struct and put everything in there.
So product name so I can call just name, which would be a string and amount would be the price per
item and that would be an end.
So that's a price per item.
And then I'd have quantity and that would be again and, and whatever else you want for per product
sales.
And then of course I would get rid of these three altogether.
I'm not going to because I want this to work.
And instead of passing just one item per request, I pass a slice of products and give it the appropriate
Jason name over here, then down when I'm printing my invoice way down here.
Instead of doing this once, I would put a range statement here, I would range through the slice of
products and print one line at a time, and that's all I would really have to do, pretty straightforward.
So everything from here to here would be inside the range, and that's pretty easy.
And I'm going to undo everything I just did because I need to save this code and put it back up there
for you.
But clearly this does what it's supposed to, so I'll get rid of this and get rid of this and we're
back to functional code, and that's a good start.
So we actually now want to comment this about uncommented this get rid of this colon on the error statement,
because there has been declared up here on line twenty seven and now we want to go back to our front
end and actually call this micro service.
But of course, before we do that, we have two more steps.
Number one, creating an email and number two, sending the email with an attachment.
And that is absolutely trivial.
We'll take care of these two steps in the next lecture and then we'll actually call this micro service
and make sure that it sends an email with an attachment.