Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
@DomainService
class TalksAdvisor(private val searchTalks: SearchTalks,
private val recommendations: Recommendations,
private val profiles: Profiles) : RecommendTalks {
override fun to(userId: String): Recommendation {
val profile = profiles.fetch(userId) ?: throw ProfileNotFoundException(userId)
return recommendTalksSatisfying(profile.preferences)
}
override fun satisfying(guestCriteria: GuestCriteria): Recommendation {
return recommendTalksSatisfying(guestCriteria as Criteria)
}
private fun recommendTalksSatisfying(criteria: Criteria): Recommendation {
val talks = retrieveTalksSatisfying(criteria)
return recommendations.save(Recommendation(criteria = criteria, talks = talks))
}
private fun retrieveTalksSatisfying(criteria: Criteria): Set<Talk> {
return searchTalks.forTopics(criteria.topics)
.filter { criteria.hasTalkFormat(it.format) }
.toSet()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.