-
Notifications
You must be signed in to change notification settings - Fork 1
Data Layer Repository
This layer will implement a Repository pattern to make the process of getting data transparent to the programmer (I don't care if the data comes from an endpoint, db or cache) making use of Functional Approach using Arrow to improve error management in it.
Image with and example of the Repository pattern:
The structure of the Data layer is all about implementing the Repository Pattern to make data query and commands transparent to the developer and the Domain layer.
-
Repository (in this case
authenticationRepository) that will make data process transparent to the domain -
Entity (in this case
accessTokenEntity) that will manage data that comes from database, endpoints etc -
DataStore (in this case
authenticationDataStore) that will provide factory to initialize network things, database things, cache things etc -
Service (in this case
authenticationService) that will wrap network calls (in this case fake but in the future real ones) -
DAO (in this case
authenticationDAO) that will take care of Database calls, like inserting or deleting objects -
API (in this case
authenticationAPI) that will take care of Endpoints calls. By the moment is a fake class, reaching nothing, but in the future can make use of Retrofit to make calls to other APIs
AuthenticationRepository
Repository will act as a Interface that will be accessed from Domain layer to provide useful actions like login, logout, store tokens etc.
To be able to make this process transparent, the AuthenticationRepository implements the interface to decide where to pick data from (Network, Database etc)
AuthenticationDataStore
As you can see, DataStore is a factory of different kind of Storing systems (Network, Database, Cache etc).
AuthenticationEntity
Entity receives information from the data layer, and parse that information to the Domain object.
AuthenticationService
As you can see, the Service is taking care of API calls and wrapping them in a Try, to manage errors in a functional way. The API is lazy loaded becase at the moment it do not have dependencies to inject and in the future we may use Retrofit to implement endpoint calls.
AuthenticationDAO
Dao is taking care of DB calls. By the moment I'm using SharedPreferences as I'm just storing a String, but for the future we can make use of Room to store User and the AccessToken related to him.
AuthenticationAPI
As yo can see, this class is just faking an endpoint call. If credentials are correct, then I am returning a random sessionToken, if not throwing an exception to simulate endpoint calls.







