Closed Abolfazl-MI closed 2 years ago
has information about the repository in our readme, I need to clean this repo but I will probably do another one encompassing this pattern applied in other sectors such as backend, other fornts and etc, that's what I've been working on lately.
But to be blunt, a repository, in our context, is just a place to store the functions that connectan controller <-> api
That is, you can have a function to add user in your api, and use it from several different controllers/modules such as adding a user to a group, or adding a user to an establishment for example.
By creating a repository per module, you can reuse this function by just pointing it, located in the api, to your repository, which will be consumed in your controller.
//example api
class API extends GetConnect{
deleteUser(id)async{
....
}
createUser(user) async {}
editUser(user) async {}
}
//modulo usuarios
class UsersRepository {
final API api;
...
deleteUser(id) => api.deleteUser(id);
createUser(user) => api.createUser(user);
}
class UsersController extends GetxController{
final UsersRepository repository;
.....
createUser(id) async => await repository.createUser(id);
deleteUser(id) async => await repository.deleteUser(id);
}
//modulo my clients
class MyClientsRepository {
final API api;
...
editUser(user)=> api.editUser(user);
deleteUser(id) => api.deleteUser(id);
}
classMyClientsController extends GetxController{
final MyClientsRepository repository;
.....
editUser(user) async => await repository.editUser(user);
deleteUser(id) async => await repository.deleteUser(id);
}
sorry for long time answer.
Hello to writer ,
your article is so good but there is problem !
there is no implementation witch we can see and understand more !
for example one person like me who always use MVC doesn't know whats repository!
how to implement the repository :( please provide some code to we can read :heart: thanks