00:02
Next up is our update method, which is meant for updating a specific difficulty. Again, that ID is going to come through
00:12
our route parameters and the request is there because again, we'll need to validate our data. So let's first validate that data by doing await request validate using,
00:20
and this too is also going to use our difficulty validator just like our create method did. They both take in the same body payloads, so they can both use the same validator there. Again, just like our create,
00:30
we also have an update difficulty action that we can make use of that also returns back the updated difficulty to the caller.
00:37
So we can go ahead and const difficulty equals await, update difficulty, import and call the handle method
00:45
for that action, and we need to grab the organization out of our HTTP context, pass that into the handle method as well as our ID that we're wanting to update
00:55
as our programs ID, and then the data as well. I'm gonna go ahead and break that down onto separate lines like so, make it a little bit more legible
01:03
and move the one that we are defining up to the top. And now we can go ahead and just return back that difficulty, you could also return directly from that call there as well if you wish.
01:12
So we pass in this specific ID that we're looking to update, this action will then query for that specific ID, update it with the passed in data payload,
01:21
and then return that updated difficulty back to us, which we are returning as the response of our API call there. So jumping back into Hopscotch,
01:31
we can create a new request called update difficulty, save that, switch this now from a get to a put because we're updating it,
01:41
we wanna leave the URL the same here to update our difficulty with an ID of 10, and we wanna add a body back into this request as application JSON.
01:50
This body should take in the updated payload for the difficulty itself. So we'll pass in a name, and I believe the name of this was API test two,
02:00
so we'll call this API test two hyphen edited, and then we'll add in a color of maybe 00FF00 there to make it evident that it's been changed.
02:10
Let's send this on off and look at that, we get back a 200 status response with our body of our name, API test two edited,
02:17
our color of 00FF00, so all looks a-okay there. Furthermore, if we jump back to our get difficulty, send this off one more time,
02:27
we get back the same edited result, further confirming that it has indeed been updated inside of our database. All right, let's jump back to that put request, make sure that we save that,
02:36
and if we were to try and send off a very long string that would not be valid, send that off, we get back an error for the max length of the name field,
02:46
and it also provides what that max is to us as well, cool. Let's go ahead and update this back to how we had it, at least for the name, send that off, and we're good to go.