blob: c28c5b46255b99a1fdca2395d5967d68c4b84903 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
package xyz.driver.pdsuidomain.formats.json.intervention
import play.api.libs.functional.syntax._
import play.api.libs.json.{Format, JsPath}
import xyz.driver.pdsuicommon.domain.LongId
import xyz.driver.pdsuidomain.entities.InterventionType
import xyz.driver.pdsuidomain.entities.InterventionType.DeliveryMethod
final case class ApiInterventionType(id: Long, name: String, deliveryMethods: List[String]) {
def toDomain = InterventionType(id = LongId[InterventionType](id), name = name)
}
object ApiInterventionType {
implicit val format: Format[ApiInterventionType] = (
(JsPath \ "id").format[Long] and
(JsPath \ "name").format[String] and
(JsPath \ "deliveryMethods").format[List[String]]
)(ApiInterventionType.apply, unlift(ApiInterventionType.unapply))
def fromDomain(interventionType: InterventionType) = {
val typeMethods = InterventionType.deliveryMethodGroups.getOrElse(interventionType.id, Set.empty[DeliveryMethod])
ApiInterventionType(
id = interventionType.id.id,
name = interventionType.name,
deliveryMethods = typeMethods.map(DeliveryMethod.methodToString).toList
)
}
}
|