Showing user specific Shopping Lists
To show a user-specific Shopping List, we need to scope our database query. Currently, the database query fetches all resources of the type being requested. We need to search for resources in the database that contain user ID that equals  the user ID of the requesting user. This can be done by overriding two methods in our ShoppingListController, which inherits from BaseResourceController. The two methods we need to override are the index and the store method.
In the index method, we need to query for all Shopping Lists which contains the user ID of the user making the request, and in the store method, we need to set the userId property to the user ID of the user making the request before saving the user record in the database. To make this work the way we want, we need to follow these steps:
- Open the
ShoppingListController.swiftfile, and inside the class, override theindexmethod with this implementation. In this method, we added one line to get the...