Use Cases
Explore how to implement use cases that encapsulate business logic within a clean architecture framework using Python. Learn to interact with repository interfaces, perform basic data retrieval without filters, and write tests using mocking techniques and pytest. Understand when to use simple functions versus classes for your use case implementations to keep your code maintainable and aligned with clean architecture principles.
We'll cover the following...
It’s time to implement the actual business logic that runs inside our application. Use cases are the places where this implementation happens, and they may or may not be directly linked to the external API of the system. The simplest use case we can create fetches all the rooms stored in the repository and returns them. In this first section, we won’t implement any filters to narrow our search. Instead, we’ll introduce code that utilizes filters in the next lesson, “Error Management in a Use Case,” where we’ll discuss error management.
Impact on our test case
Our repository is our storage component. Following the structure of clean architecture, this will be implemented into the external systems layer, which, as we mentioned earlier, is the outer layer. We’ll access this repository as an interface. In ...