Summary
Highlights
The video revisits the interior architecture roadmap, focusing on building a service repository. It explains that a service repository acts as a layer of abstraction over the regular repository's CRUD methods, providing specific, reusable functionalities composed of these basic repository methods. This abstraction simplifies code and improves maintainability by hiding implementation details from the controller.
The first step in coding the services for clubs is to create a 'service' folder and an interface called 'ClubService'. This interface will declare methods that the service will implement, ensuring a decoupled architecture. Initially, a simple 'findAll' method is added to retrieve all clubs.
An implementation file, 'ClubServiceImpl', is created as a class that implements the 'ClubService' interface. This class will contain the actual logic for the service methods. It injects the 'ClubRepository' to utilize its methods, demonstrating how service methods abstract the underlying data access operations.
The video highlights the necessity of Data Transfer Objects (DTOs) and mappers. When retrieving data from the database, it's often returned as an entity model. To shape this data for specific views, enhance security, and ensure type compatibility, it needs to be transformed into a DTO. A mapper function is introduced to facilitate this conversion, taking a 'Club' entity and converting it into a 'ClubDto' using a builder pattern. This ensures that only necessary data is exposed to the presentation layer.
A detailed explanation of how to create the mapper method is provided. This method, `mapToClubDto`, takes a `Club` object as input and constructs a `ClubDto` using a builder pattern, populating its fields with corresponding data from the `Club` object. This manual mapping is recommended over automatic mappers for better control and understanding in production environments.