Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ASK] Best Practices For Merging Network Call Data into Custom Model. #313

Closed
mezzav opened this issue May 15, 2024 · 0 comments
Closed

Comments

@mezzav
Copy link

mezzav commented May 15, 2024

Hello,

I am having some trouble wrapping my head around how to handle multiple network calls (probably because I am new to kotlin and android development). Given two network calls, A and B, which are not dependent on each other, how would I go about "merging" the data from both network calls into a custom model.

It is similar to the example provided in the Google article regarding the Domain Layer

I am thinking a nested .onSuccess lambda might work but not sure if it would be best practice. I was looking at the Model Mapper documentation but I am a bit confused on how to use it in this case. Would a Flow approach be better even though this would be a one-shot network call?

class GetMovieDetailsWithCast @Inject constructor(
    private val repository: NetworkTMDBRepository,
) {
    suspend operator fun invoke(id: Int) {
        val movie =  repository.fetchMovieDetails(id) // ApiResponse<NetworkMovieDetails>
        val credits = repository.fetchMovieCredits(id) // ApiResponse<NetworkMovieCredits>

        /* do some processing here */

        MovieDetailsWithCredits(movie = movie, credits = credits) // where movie and credits are  of NetworkMovieDetails and NetworkMovieCredits

    }
}

Thanks in advance.

@mezzav mezzav closed this as completed May 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant