Skip to content

Instantly share code, notes, and snippets.

@kozmi55
Created July 28, 2017 14:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kozmi55/7d4d38f8e8bbacdb687574169f985587 to your computer and use it in GitHub Desktop.
Save kozmi55/7d4d38f8e8bbacdb687574169f985587 to your computer and use it in GitHub Desktop.
class UserRepository(
private val userService: UserService) {
fun getUsers(page: Int) = userService.getUsers(page)
fun getDetails(userId: Long) : Single<DetailsModel> {
return Single.zip(
userService.getQuestionsByUser(userId),
userService.getAnswersByUser(userId),
userService.getFavoritesByUser(userId),
Function3<QuestionListModel, AnswerListModel, QuestionListModel, DetailsModel>
{ questions, answers, favorites ->
createDetailsModel(questions, answers, favorites) })
}
private fun createDetailsModel(questionsModel: QuestionListModel, answersModel: AnswerListModel,
favoritesModel: QuestionListModel): DetailsModel {
val questions = questionsModel.items
.take(3)
val favorites = favoritesModel.items
.take(3)
val answers = answersModel.items
.filter { it.accepted }
.take(3)
.map { AnswerViewModel(it.answerId, it.score, it.accepted, "TODO") }
return DetailsModel(questions, answers, favorites)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment