aboutsummaryrefslogtreecommitdiff
path: root/src/main/scala/xyz/driver/pdsuidomain/formats/json/hypothesis/ApiHypothesis.scala
blob: bf18a6021ac1d9b1de5452c9e66f7f3d761337d9 (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
31
32
33
34
35
package xyz.driver.pdsuidomain.formats.json.hypothesis

import java.util.UUID

import play.api.libs.functional.syntax._
import play.api.libs.json.{Format, JsPath}
import xyz.driver.pdsuicommon.domain.UuidId
import xyz.driver.pdsuidomain.entities.Hypothesis

final case class ApiHypothesis(id: UUID, name: String, treatmentType: String, description: String) {

  def toDomain = Hypothesis(
    id = UuidId[Hypothesis](id),
    name = name,
    treatmentType = treatmentType,
    description = description
  )
}

object ApiHypothesis {

  implicit val format: Format[ApiHypothesis] = (
    (JsPath \ "id").format[UUID] and
      (JsPath \ "name").format[String] and
      (JsPath \ "treatmentType").format[String] and
      (JsPath \ "description").format[String]
  )(ApiHypothesis.apply, unlift(ApiHypothesis.unapply))

  def fromDomain(hypothesis: Hypothesis) = ApiHypothesis(
    id = hypothesis.id.id,
    name = hypothesis.name,
    treatmentType = hypothesis.treatmentType,
    description = hypothesis.description
  )
}