Skip to content

Instantly share code, notes, and snippets.

@beyondxscratch
Created August 10, 2020 00:25
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 beyondxscratch/b087d5eb9e02f8d1f4ac839892e811ca to your computer and use it in GitHub Desktop.
Save beyondxscratch/b087d5eb9e02f8d1f4ac839892e811ca to your computer and use it in GitHub Desktop.
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