Skip to content

My all accounts #325

@suryavanshishanty227-commits

Description

It seems like your original solution had a data module dependency trying to be used in the domain module. In this architecture, that is not possible.

To keep in-line with what @android10 has created, you may have to create a LoginRepository (or just add a login function to the UserRepository in the existing implementation) like so:

public interface LoginRepository {
    Observable logUserIn(String email, String password)
}

Still in the domain layer, have a LoginUseCase that uses the LoginRepository as a component, like so:

public class LoginUseCase extends UseCase {

  private final int userId;
  private final LoginRepository loginRepository;
  private final String email;
  private final String password;

  @Inject
  public LoginUseCase(int userId, LoginRepository loginRepository,
      ThreadExecutor threadExecutor, PostExecutionThread postExecutionThread, 
       String email, String password) {
    super(threadExecutor, postExecutionThread);
    this.userId = userId;
    this.loginRepository = loginRepository;
    this.email = email;
    this.password = password;
  }

  @Override protected Observable buildUseCaseObservable() {
    return this.loginRepository.logUserIn(email, password);
  }
}

The data layer process might be a bit more involved. This is where you would actually implement your repository pattern for the login case. If you want some sort of login persistence, you will need to implement some form of SharedPreferences or SQLite for storing the data on a successful login, as well as an API to handle the initial request. I won't get too much into that here, as it is quite involved depending on your implementation.

In the presentation layer, you would inject your LoginRepository from the domain layer to use wherever that dependency is needed. It would be advantageous to check if a user is logged in, and have signOut and other important methods in the repository to maintain persistence.

This isn't a great implementation by any means, and may even be too complex for your needs. I'm still learning how this architecture works myself, and this is just how I see that a login implementation may work.

Hope this helps.
Let me know if you have any questions.

Originally posted by @Weava in #158

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions