aboutsummaryrefslogtreecommitdiff
path: root/src/main/scala/xyz/driver/pdsuidomain/formats/json/export/ApiExportTrialArm.scala
blob: ea96f58412f06f23d196856c9a1e447b10bced05 (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
package xyz.driver.pdsuidomain.formats.json.export

import play.api.libs.functional.syntax._
import play.api.libs.json._
import xyz.driver.pdsuicommon.domain.LongId
import xyz.driver.pdsuidomain.entities.Arm
import xyz.driver.pdsuidomain.entities.export.trial.ExportTrialArm

final case class ApiExportTrialArm(armId: String, armName: String) {

  def toDomain: ExportTrialArm = {
    ExportTrialArm(LongId[Arm](armId.toLong), armName)
  }
}

object ApiExportTrialArm {

  implicit val format: Format[ApiExportTrialArm] = (
    (JsPath \ "armId").format[String] and
      (JsPath \ "armName").format[String]
  )(ApiExportTrialArm.apply, unlift(ApiExportTrialArm.unapply))

  def fromDomain(arm: ExportTrialArm) = ApiExportTrialArm(
    armId = arm.armId.toString,
    armName = arm.armName
  )
}