ProfileCreator.kt 680 Bytes
Newer Older
Julien Topçu's avatar
Julien Topçu committed
1 2
package org.craftsrecords.talkadvisor.recommendation.profile

Julien Topçu's avatar
Julien Topçu committed
3
import org.craftsrecords.hexarch.DomainService
Julien Topçu's avatar
Julien Topçu committed
4 5 6 7
import org.craftsrecords.talkadvisor.recommendation.api.CreateProfile
import org.craftsrecords.talkadvisor.recommendation.preferences.Preferences
import org.craftsrecords.talkadvisor.recommendation.spi.Profiles

Julien Topçu's avatar
Julien Topçu committed
8 9
@DomainService
class ProfileCreator(private val profiles: Profiles) : CreateProfile {
Julien Topçu's avatar
Julien Topçu committed
10 11
    override fun forUserWithPreferences(userId: String, preferences: Preferences): Profile {
        val profile = Profile(userId, preferences)
Julien Topçu's avatar
Julien Topçu committed
12 13
        profiles.fetch(userId)?.let { throw ProfileAlreadyExistsException(userId) }
        return profiles.save(profile)
Julien Topçu's avatar
Julien Topçu committed
14 15
    }
}