-3

I have a question about where should I get the info required for making an api call.

Let's say I have this :

Presenter --> Use Case --> DataSource --> Api

Ok now to do my api call, I need a userId, languagueCode, etc.. for instance, and I have use-case to get that info, also a datasource . My question is, where should I get that info: in use-case or data-source?

If I do it in the data-source it should be like :

class MyUseCase @Inject constructor(getUserUsecase: GetUserUsecase, getLanguagueCodeUsecase: GetLanguagueCodeUsecase, myDataSource: DataSource) {

operator fun invoke(optionClicked: String) {
  myDataSource.getFoo(
     getUserusecase.invoke().id,
     getLanguagueCodeUsecase.invoke(),
     optionClicked,
  )
}

}

Or if I do it in datasource, should I use the use-case or the data-sources to get that info?

If the question was not clear, shorter question is:

If I have an api call that needs attributes that doesn't come from my presentation layer (like countryId, userId, etc) where should I get them, in the use-case and send it directly to the datasource or my use-case only needs to send what comes from presentation and then in datasource ask for everything I need, like countryCode and userId? (Using use-case or datasource) ?

2
  • 2
    Welcome to stack exchange! I encourage you to head over to the help center to see more of how the stack exchange format works. It could be difficult to answer your question because "discussions," as you call it in the first sentence, are not good fits for the question & answer format. It tends to result in the questions getting quickly closed.
    – Cort Ammon
    Commented Sep 15, 2021 at 14:56
  • @CortAmmon: the word "discussion" in the first sentence was pretty irrelevant to the question, I took the freedom to remove it.
    – Doc Brown
    Commented Sep 16, 2021 at 4:36

1 Answer 1

1

This a pretty simple question with a pretty simple answer. No real "discussion" is necessary.

Looking at the image on Mr. Martin's blog entry you will see that all external data comes from the Frameworks and Drivers layer. Whether it's stored in a DB or entered by the user through the UI, pulled in from an external device or whatever. The data comes in from the outermost layer and is pushed into the rules that exist at the inner most layers.

So your countryID or userID come from the UI or a DB or the OS of the device the app is running on or some other effectual place in the outermost layer, into your use-case through some sort of controller or gateway. Then your use-case sends that information, possibly after updating or adjusting it, through some sort of presenter or gateway to the external interface (your network layer.)

This architecture is also called Ports and Adapters, Hexagonal or the Onion Architecture.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.