00:02
- So of course this controller here is looking pretty good. The only thing that we have left to do within this controller is our actual show method. And this is the controller method
00:12
that's going to handle our input for getting a specific courses details. And for that, we're also going to want to get the modules and lessons for that course as well. So that's a completed package
00:22
for our users implementing our API. So as always, very first thing that we wanna do is get our organization so that we can authorize its token. And since we're showing,
00:32
that's gonna be a read operation and we'll just pass the organization on in there. Now we've already done all the legwork for this in our previous series. This is already baked into an action.
00:42
So if we go into actions courses, we have this get course action that accepts in the ID of the course that we're after as well as the organization. And then it will query the course off of the organization
00:52
for the specific ID that we passed. Pre-loading in the access level, difficulty and status as we've seen previously,
00:59
but then it will also side load the modules for that course. And then within the modules will also reside the lessons per module. With each module, we're pre-loading the status
01:08
and then ordering it by its order field. And we're doing a similar thing for our lessons, pre-loading the access levels and status and then ordering it by its order field.
01:16
And this is kicked back from the action as an object with a course property and a modules property within it. So although the modules could be directly pre-loaded onto the course, in this action,
01:26
we're separating them out into two separate properties. The primary reasoning behind that, if we were to jump back into our browser and go into one of our courses
01:35
is because those are visually separated entities, right? You have the courses details up at the top and then you have the module and lessons information in a completely separate section.
01:45
So while they're related, they can be treated as separate entities. And down the road, if you wish, what that would allow you to do is have a specific endpoint for just refreshing the module and lesson list
01:55
so that you don't have to also get the courses details if you just need to refresh the modules and lessons. So just having those separated out of the bat
02:04
would make that refactoring a little bit easier down the road should it need to happen. So within our courses controller show method, all that we need to do is call this action
02:13
and let's plop its return into a data property. Since there's already a course property that's going to be within it, we don't wanna do course.course
02:20
and set that equal to await, get course, import that action, call the handle method and let's pass in the ID as params.id
02:30
and then our organization. Next, we just need to return that data. And of course, if you wanted to, we could just return direct from the action as well
02:39
doing just that and we get back the exact same thing. So awesome, that should do it for our get courses. Let's go ahead and jump back in the Hopscotch then.
02:48
Let's add in our new request for our get course and we can save that. This too will be a get method, but rather than doing slash courses,
02:56
we wanna do slash courses slash and then provide the route parameter for the ID that we're after. So let's remind ourselves what our IDs are here.
03:05
So the first course that we were just looking at within our web GUI looks to have an ID of one. So let's go ahead and work with that one. So we'll jump back over into our get course,
03:14
plop an ID of one into there and send that off. And perfect, we get back our course property and our modules property, our course being an object
03:23
with the actual courses details within it. This will look relatively similar to the paginated list details. And then we also have the modules,
03:32
which is an array of objects consisting of our modules information, its status and the lessons within that module.
03:40
So we can see module one has two different lessons and then we get down to the second module, which I believe has one lesson as we saw in the GUI or within our web app there.
03:50
So awesome, that matches one to one with our expectations.