Skip to content

Instantly share code, notes, and snippets.

@esilverberg
Created November 24, 2020 16:07
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 esilverberg/9ea87435561a2eb8169a6e74692cb174 to your computer and use it in GitHub Desktop.
Save esilverberg/9ea87435561a2eb8169a6e74692cb174 to your computer and use it in GitHub Desktop.
// 🍎
class PSSMatchRepository {
private let kPrefsHasShownMatchInstructionsKey = "has_shown_match_instructions"
private let api: PSSMatchApiImplementing
private let prefs: PSSPrefsStoreImplementing
init(api: PSSMatchApiImplementing,
prefs: PSSPrefsStoreImplementing) {
self.api = api
self.prefs = prefs
}
var hasShownInstructions: Bool {
get {
return prefs[kPrefsHasShownMatchInstructionsKey] ?? false
}
set {
prefs[kPrefsHasShownMatchInstructionsKey] = newValue
}
}
func matchStack(location: CLLocationCoordinate2D, browseMode: PSSBrowseMode?, loadMore: Bool) -> SignalProducer<PSSMatchStack, Error> {
return api.getMatchStack(location: location,
browseMode: browseMode,
loadMore: loadMore)
}
func rate(profile: PSSProfile, rating: PSSProfileRating) -> SignalProducer<Void, Error> {
return api.postRate(profile: profile, rating: rating)
}
func askMeTomorrow(profile: PSSProfile) -> SignalProducer<Void, Error> {
return api.postRateReminder(profile: profile)
}
func deleteRating(profile: PSSProfile) -> SignalProducer<Void, Error> {
api.deleteRating(profile: profile)
}
}
// 🤖
class MatchRepository(private val matchApi: IMatchApi,
private val prefs: IPrefsStore) {
companion object {
private const val PREF_HAS_SHOWN_MATCH_INSTRUCTIONS = "has_shown_match_instructions"
}
var hasShownInstructions: Boolean
get() = prefs.getBoolean(PREF_HAS_SHOWN_MATCH_INSTRUCTIONS, false)
set(value) = prefs.putBoolean(PREF_HAS_SHOWN_MATCH_INSTRUCTIONS, value)
fun getMatchStack(location: PSSLocation, loadMore: Boolean) = matchApi.getMatchStack(location, loadMore)
fun rate(profile: Profile, rating: Profile.ProfileRating) = matchApi.postRate(profile, rating)
fun askMeTomorrow(profile: Profile) = matchApi.postRateReminder(profile)
fun deleteRating(profile: Profile) = matchApi.deleteRating(profile)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment