Outline

Exercise: Follow and Unfollow

In the Conduit.Api Project, modify the ProfilesController by adding the following methods:

Method #1
  • Name: FollowAsync
  • Return Type: IActionResult
  • Parameters: [FromRoute] string userName
Add the following Attribute to the method:

HttpPost("{userName}/follow")

Add the following code to the body of the method:
    UserProfile userProfile = await ProfileRepo.FollowAsync(userName);
    return Ok(new { userProfile });

Add the try…catch block to catch ProfileNotFoundException & Exception

Method #2
  • Name: UnfollowAsync
  • Return Type: IActionResult
  • Parameters: [FromRoute] string userName
Add the following Attributes to the method:

HttpDelete("{userName}/follow")

Add the following code to the body of the method:
    UserProfile userProfile = await ProfileRepo.UnfollowAsync(userName);
    return Ok(new { userProfile });

Add the try…catch block to catch ProfileNotFoundException & Exception.

Hover over the errors, select [Show Potential Fixes] and Select [Generate method].

In the next video I'll show you the solution I came up with.

 

I finished! On to the next chapter