The Repository

Let’s learn the role of the repository in clean architecture.

Exception from the previous lesson

If we run the Flask development web server now and try to access the /rooms endpoint, we’ll get the following response:

{"type": "SystemError", "message": "TypeError: list() got an unexpected keyword argument 'filters'"}

The HTTP 500 error we see in the HTTP response is exactly the same as the mapping of our SystemError use case error, which in turn signals a Python exception.

Update the repository

This error comes from the repository, which hasn’t been migrated to the new API. To tackle this, we need to change the list method of the MemRepo class so that it accepts the filters parameter and acts accordingly. This is a critical step. The filters may have been considered part of the business logic and implemented in the use case itself. Still, we decided to leverage what the storage system can do, so we moved to filter in that external system.

This is a reasonable choice to make because databases can usually perform filtering and ordering very well. Even though the in-memory storage we’re currently using isn’t a database, we’re preparing to use real external storage.

Impact test case

The new version of repository tests is as follows:

Get hands-on with 1400+ tech skills courses.