the-algorithm/follow-recommendations-service/common/src/main/scala/com/twitter/follow_recommendations/common/utils/DisplayLocationProductConverterUtil.scala
twitter-team ef4c5eb65e Twitter Recommendation Algorithm
Please note we have force-pushed a new initial commit in order to remove some publicly-available Twitter user information. Note that this process may be required in the future.
2023-03-31 17:36:31 -05:00

28 lines
1.1 KiB
Scala

package com.twitter.follow_recommendations.common.utils
import com.twitter.follow_recommendations.common.models.DisplayLocation
import com.twitter.follow_recommendations.common.models.Product
import com.twitter.product_mixer.core.model.marshalling.request.Product
object DisplayLocationProductConverterUtil {
def productToDisplayLocation(product: Product): DisplayLocation = {
product match {
case Product.MagicRecs => DisplayLocation.MagicRecs
case _ =>
throw UnconvertibleProductMixerProductException(
s"Cannot convert Product Mixer Product ${product.identifier.name} into a FRS DisplayLocation.")
}
}
def displayLocationToProduct(displayLocation: DisplayLocation): Product = {
displayLocation match {
case DisplayLocation.MagicRecs => Product.MagicRecs
case _ =>
throw UnconvertibleProductMixerProductException(
s"Cannot convert DisplayLocation ${displayLocation.toFsName} into a Product Mixer Product.")
}
}
}
case class UnconvertibleProductMixerProductException(message: String) extends Exception(message)