So let's get started improving this get widget function in models don't go, but before we do that,
I have a little thing I want to change here just for consistency.
Back up at the very top, I have widget I.D. in the order type with a lowercase and that's not good
practice.
When you have an ID go really likes things to be with a capital I and a capital D so I did it there
and let's see if I did it anywhere else.
Transaction status that should be in case, and this is just a just a convention that you'll find in
most go programming shops.
OK, so that works better.
So those are all fixed up.
Now, what do I want to select from my database right now?
I'm saying select ID and name from widgets, and we want more than that.
So let's bring up our database again.
Just look at the column names.
So under widgets structure, I have already name, description, inventory level, so I'd name what
I'm going to do is wrap this whole thing in back ticks just so I can put it on multiple lines so it's
a little more readable.
So I'll I'll say and I'll just put this right down here like that so it's more nicely formatted select.
I'd name description.
And let's go back and look at the column names, inventory level price in the entry level price and
back again.
Then I have image and created an updated I'll do it in that order image and on the next line created
and updated that from intent that here widgets where the back ID equals the perfect.
So now of course we're scanning more than just ID and names.
We'll have to change this line.
And what I'll do is just duplicate this a few times to save some typing so that my name, description
and inventory level than price than image
and we may as well get created a.
And updated it.
OK, now the only change I'm going to make here is there may be situations where we don't have an image.
And what I could do is take advantage of the skill and all types that are built into our database environment
or built in to go.
But what I'll do instead is just coalesce.
It just saves some programming.
I'll take image if it has a value, otherwise put it in an empty string.
OK, so that should get the necessary information from the database, which is a good start.
Now what I want to do next is to modify this route.
Let me go to rootstock, go modify this from charge wants to say widgets and then the idea of the widget.
I can do that right now say slash widget slash and then the idea.
OK, and just as we did on the back end, I can go to the handlers for this.
And find the charge once handler.
And get the ID right from the URL, so let's just copy and paste from our handlers API, let's copy
these two lines and copy this one as well.
Copy those and go back to our handlers and paste that right here and get rid of this widget bit.
And we'll have to import these as Takio and see, and that should take care of the imports for us.
So now when we come to this you URL, or does this handler charge once will grab the ID from the Eurail
itself, convert it to an end color database function, and then we have our widget and we can pass
that into the appropriate template.
And this is actually pretty effective.
So that means, of course, that I'll have to find my templates and I have an area somewhere.
Let's see what that is.
Safeness that there were just an unused important saving it got rid of it.
The ID took care of that for me.
Let's go back to our base layout and find the bi ones and change it to slash widget one because we only
have one widget and that'll work for now.
OK, so let's open our terminal.
Look at this.
Looks good.
OK, everything seemed to compile properly.
Let's go back to our front end on the web browser and I'll go to virtual terminal.
OK, and now this product's menu should be updated to the correct world and it looks like it is.
Let's see if we got it right.
And there it is.
OK, so it's displaying the necessary information now that price should have come from the actual price
itself and so should this description.
So if I actually go in and change the value in the database, this should now update.
All right.
This is a good start.
Now, there's more things we want to do.
For example, we don't want to have the image hardcoded and we actually want to take care of the writing
of a transaction to the database.
But we'll get started on that sort of thing in the next lecture.