Reputation: 62559
So I have an app that uses firebase for login and to store data also we use a firebase DB table.
The app has a login with google button so, if the google account is verified, I pass the account to firebase to store it in a db. After the account is created/fetched I store the users profile in a firebase DB table as well. So my question is about repositories using uncle bob's clean architecture approach.
Should I create a repository for google login and then one for profile? I mean, if we take a look at the usecases (interactors) there should be a googleAPIInteractor
and a firebaseInteractor
right? Or should I just create
a single interactor called UserDataInteractor
? Do you see what I mean? I'm confused on how many repositories I should create. I think that each new repository would have its own interactor, 1:1 right?
Let's take a look at what I'm trying to achieve:
in the presenter code (assuming MVP architecture) I'd do this:
public class MyPresenter extends PresenterBase {
@inject someGoogleAPIInteractor i1;
@inject somefirebaseInteractorInteractor i2;
//both these repo's are using firebase so should i just use 1 repo instead ?
//.....
public void doLogin(String googleAccount){
i1.fetchOrCreateGoogleLogin(,googleAccount,someSubscriber);
//RXJava async call, not important. but it confirms google account and then in subscriber authenticates into firebase account for my app
}
public void getProfile(String firebaseAccount) {
//this just gets stuff about the user like order history, name , etc
i2.getFirebaseProfile(firebaseAccount,someOtherSubscriber);
}
the interactors i injected here would use their own repo's. one called
@inject someGoogleAPILoginRepository r1; //in i1
//and another in i2 called:
@inject someFirebaseProfileRepository r2;
i1 connects to google API to authenticate google account and then I will use i2 in the callback to create a profile.
So what I'm doing currently is that google API has a repo and firebase has a repo, and I have two separate interactors, is that acceptable? The thing is for the google repo, I'm not storing anything. I am just using it so I have an account to login to firebase with.
Upvotes: 0
Views: 1429
Reputation: 2660
'Repository' is mentioned in Clean Architecture is a design pattern and not an implementation.
It is applied for Data layer and works as a central place to manipulate your app's data from all sources (both remote or local).
A good practice is that you have a repository and its helper class in one place (a module or package).
There are several good examples from out there that you can take a look.
1. Android10's sample
2. Ribot's guideline
3. Google sample
Upvotes: 0