aboutsummaryrefslogtreecommitdiff
path: root/src/main/scala/xyz/driver/pdsuidomain/formats/json/hypothesis/ApiHypothesis.scala
blob: 7446ec32238b1abff9f7d3c26d3271fe8411ad93 (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
package xyz.driver.pdsuidomain.formats.json.hypothesis

import java.util.UUID

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

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

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
  )
}