Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
package org.craftsrecords.talkadvisor.recommendation.spi.stubs
import org.craftsrecords.hexarch.Stub
import org.craftsrecords.talkadvisor.recommendation.preferences.Topic
import org.craftsrecords.talkadvisor.recommendation.spi.SearchTalks
import org.craftsrecords.talkadvisor.recommendation.talk.Talk
import org.craftsrecords.talkadvisor.recommendation.talk.TalkFormat
import java.util.*
@Stub
class HardCodedTalksSearcher : SearchTalks {
override val maxNumberOfTalks: Int = 5//ignored value
override fun forTopics(topics: Set<Topic>): Set<Talk> {
return createTalks(topics)
}
private fun createTalks(topics: Set<Topic>): Set<Talk> {
return topics.flatMap { createTalksForTopic(it.name) }.toSet()
}
private fun createTalksForTopic(topicName: String): Set<Talk> {
return TalkFormat.values().map {
Talk.with {
id = UUID.randomUUID().toString()
title = "${it.name} $topicName"
duration = it.durationRange.start.plusSeconds(30)
}.build()
}.toSet()
}
}
package org.craftsrecords.talkadvisor.recommendation.spi.stubs
import org.craftsrecords.hexarch.Stub
import org.craftsrecords.talkadvisor.recommendation.profile.Profile
import org.craftsrecords.talkadvisor.recommendation.spi.Profiles
@Stub
class InMemoryProfiles(private val profiles: MutableMap<String, Profile> = HashMap()) : Profiles {
override fun fetch(userId: String): Profile? {
return profiles[userId]
}
override fun save(profile: Profile): Profile {
profiles[profile.id] = profile
return profile
}
}
package org.craftsrecords.talkadvisor.recommendation.spi.stubs
import org.craftsrecords.hexarch.Stub
import org.craftsrecords.talkadvisor.recommendation.Recommendation
import org.craftsrecords.talkadvisor.recommendation.spi.Recommendations
import java.util.*
@Stub
class InMemoryRecommendations(private val recommendations: MutableMap<UUID, Recommendation> = HashMap()) : Recommendations {
override fun save(recommendation: Recommendation): Recommendation {
recommendations[recommendation.id] = recommendation
return recommendation
}
}
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.