{"action":"created","issue":{"url":"https://api.github.com/repos/android10/Android-CleanArchitecture/issues/55","labels_url":"https://api.github.com/repos/android10/Android-CleanArchitecture/issues/55/labels{/name}","comments_url":"https://api.github.com/repos/android10/Android-CleanArchitecture/issues/55/comments","events_url":"https://api.github.com/repos/android10/Android-CleanArchitecture/issues/55/events","html_url":"https://github.com/android10/Android-CleanArchitecture/issues/55","id":110373224,"number":55,"title":"Can I use this architecture in real project?","user":{"login":"sitexa","id":7471477,"avatar_url":"https://avatars.githubusercontent.com/u/7471477?v=3","gravatar_id":"","url":"https://api.github.com/users/sitexa","html_url":"https://github.com/sitexa","followers_url":"https://api.github.com/users/sitexa/followers","following_url":"https://api.github.com/users/sitexa/following{/other_user}","gists_url":"https://api.github.com/users/sitexa/gists{/gist_id}","starred_url":"https://api.github.com/users/sitexa/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sitexa/subscriptions","organizations_url":"https://api.github.com/users/sitexa/orgs","repos_url":"https://api.github.com/users/sitexa/repos","events_url":"https://api.github.com/users/sitexa/events{/privacy}","received_events_url":"https://api.github.com/users/sitexa/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2015-10-08T04:56:03Z","updated_at":"2015-10-08T09:31:09Z","closed_at":null,"body":"This is not an issue.\r\nIt's really a clearly defined architecture. A lot of technologies are introduced into the architecture, I 've never used them before, Dagger, RxAndroid, Butternife, etc. \r\nBut I am little confused by the fine defined UseCases, for example , GetUserList, GetUserDetails for user usecases. If I want to do user search, I must define SearchUser usecase, I want to do CRUD for many many Objects, I need to write hands of usecases separately. \r\nAnd, I'm not sure how to pass parameters to the usecases. For example, GetUserDetails, pass the userId by constructor in UserModule. How can I pass a search critera to SearchUser UseCase? A Map? Or a Model? Is there another way instead of constructor?\r\n\r\nThank you very much for any suggestion."},"comment":{"url":"https://api.github.com/repos/android10/Android-CleanArchitecture/issues/comments/146471551","html_url":"https://github.com/android10/Android-CleanArchitecture/issues/55#issuecomment-146471551","issue_url":"https://api.github.com/repos/android10/Android-CleanArchitecture/issues/55","id":146471551,"user":{"login":"johnwatsondev","id":12760754,"avatar_url":"https://avatars.githubusercontent.com/u/12760754?v=3","gravatar_id":"","url":"https://api.github.com/users/johnwatsondev","html_url":"https://github.com/johnwatsondev","followers_url":"https://api.github.com/users/johnwatsondev/followers","following_url":"https://api.github.com/users/johnwatsondev/following{/other_user}","gists_url":"https://api.github.com/users/johnwatsondev/gists{/gist_id}","starred_url":"https://api.github.com/users/johnwatsondev/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/johnwatsondev/subscriptions","organizations_url":"https://api.github.com/users/johnwatsondev/orgs","repos_url":"https://api.github.com/users/johnwatsondev/repos","events_url":"https://api.github.com/users/johnwatsondev/events{/privacy}","received_events_url":"https://api.github.com/users/johnwatsondev/received_events","type":"User","site_admin":false},"created_at":"2015-10-08T09:31:09Z","updated_at":"2015-10-08T09:31:09Z","body":"@sitexa I have solve this problem. Here is a not **elegant** enough solution.\r\n\r\nNo callback function. Just pass your criteria through **Varargs**.\r\n\r\nLoginPresenter.java\r\n\r\n```java\r\n  private void performLogin(String userId, String pwd){\r\n    Map<String, String> fields = new HashMap<>();\r\n    fields.put(\"userId\", userId);\r\n    fields.put(\"pwd\", pwd);\r\n\r\n    userLoginCase.execute(new LoginSubscriber(), fields);\r\n  }\r\n```\r\n\r\nUseCase.java\r\n\r\n```java\r\n  protected abstract Observable buildUseCaseObservable (Object...param);\r\n\r\n  public void execute(Subscriber useCaseSubscriber, Object...param){\r\n    subscription = buildUseCaseObservable(param)\r\n        .subscribeOn(Schedulers.from(threadExecutor))\r\n        .observeOn(postExecutionThread.getScheduler())\r\n        .lift(new OperatorSynchronousUnsubscribe())\r\n        .subscribe(useCaseSubscriber);\r\n  }\r\n```\r\n\r\nUserLoginCase.java\r\n\r\n```java\r\npublic class UserLoginCase extends UseCase {\r\n\r\n  private final UserRepository userRepository;\r\n\r\n  @Inject\r\n  public UserLoginCase(UserRepository userRepository,\r\n      ThreadExecutor threadExecutor, PostExecutionThread postExecutionThread) {\r\n    super(threadExecutor, postExecutionThread);\r\n    this.userRepository = userRepository;\r\n  }\r\n\r\n  @Override protected Observable buildUseCaseObservable(Object...param) {\r\n    return this.userRepository.userLogin((Map<String, String>) param[0]);\r\n  }\r\n}\r\n```\r\n\r\nUserRepository.java\r\n\r\n```java\r\npublic interface UserRepository {\r\n  Observable<User> userLogin(final Map<String, String> fields);\r\n}\r\n```\r\n\r\nUserDataRepository.java\r\n\r\n```java\r\n@Singleton public class UserDataRepository implements UserRepository {\r\n\r\n  private final UserDataStoreFactory userDataStoreFactory;\r\n  private final UserEntityDataMapper dataMapper;\r\n\r\n  @Inject public UserDataRepository(UserDataStoreFactory dataStoreFactory,\r\n      UserEntityDataMapper userEntityDataMapper) {\r\n    this.userDataStoreFactory = dataStoreFactory;\r\n    this.dataMapper = userEntityDataMapper;\r\n  }\r\n\r\n  @Override public Observable<User> userLogin(Map<String, String> fields) {\r\n    final UserDataStore userDataStore = this.userDataStoreFactory.createCloudDataStore();\r\n    return userDataStore.userLogin(fields).map(entity -> this.dataMapper.transform(entity));\r\n  }\r\n}\r\n```\r\n\r\nUserDataStore.java\r\n\r\n```java\r\npublic interface UserDataStore {\r\n  Observable<UserEntity> userLogin(@NonNull final Map<String, String> fields);\r\n}\r\n```\r\n\r\nCloudUserDataStore.java\r\n\r\n```java\r\npublic class CloudUserDataStore implements UserDataStore {\r\n  private final RestApi restApi;\r\n\r\n  public CloudUserDataStore(RestApi restApi) {\r\n    this.restApi = restApi;\r\n  }\r\n\r\n  @Override public Observable<UserEntity> userLogin(@NonNull Map<String, String> fields) {\r\n    return restApi.userLogin(fields);\r\n  }\r\n}\r\n```\r\n\r\nRestApi.java\r\n\r\n```java\r\npublic interface RestApi {\r\n  Observable<UserEntity> userLogin(final Map<String, String> fields);\r\n}\r\n```\r\n\r\nRestApi.java\r\n\r\n```java\r\npublic class RestApiImpl implements RestApi {\r\n  private static RetrofitAPI RETROFIT_CLIENT;\r\n\r\n  @Override public Observable<UserEntity> userLogin(final Map<String, String> fields) {\r\n    return RETROFIT_CLIENT.userLogin(fields).timeout(REQUEST_TIMEOUT, TimeUnit.SECONDS);\r\n  }\r\n}\r\n```\r\n\r\nPlease @me if have any issue. Thanks."}}