diff options
author | vlad <vlad@driver.xyz> | 2017-06-27 17:13:02 -0700 |
---|---|---|
committer | vlad <vlad@driver.xyz> | 2017-06-27 17:13:02 -0700 |
commit | 5832f63b84d7388441d1200f2442dc1e9de0225c (patch) | |
tree | 32f63acdc920c14effc3d0d2822c05c125ad49e4 /src/main/scala/xyz/driver/pdsuidomain/formats/json/trial/ApiPartialTrial.scala | |
parent | 9dd50590d4c8f8b9442d7c21ddd1def9dd453d5e (diff) | |
download | rest-query-5832f63b84d7388441d1200f2442dc1e9de0225c.tar.gz rest-query-5832f63b84d7388441d1200f2442dc1e9de0225c.tar.bz2 rest-query-5832f63b84d7388441d1200f2442dc1e9de0225c.zip |
All PDS UI domain models, API case classes, service traits and necessary utils moved to pdsui-commonv0.1.11
Diffstat (limited to 'src/main/scala/xyz/driver/pdsuidomain/formats/json/trial/ApiPartialTrial.scala')
-rw-r--r-- | src/main/scala/xyz/driver/pdsuidomain/formats/json/trial/ApiPartialTrial.scala | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/trial/ApiPartialTrial.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/trial/ApiPartialTrial.scala new file mode 100644 index 0000000..0dc1446 --- /dev/null +++ b/src/main/scala/xyz/driver/pdsuidomain/formats/json/trial/ApiPartialTrial.scala @@ -0,0 +1,44 @@ +package xyz.driver.pdsuidomain.formats.json.trial + +import java.util.UUID + +import xyz.driver.pdsuicommon.domain.{LongId, UuidId} +import xyz.driver.pdsuidomain.entities.Trial +import org.davidbild.tristate.Tristate +import org.davidbild.tristate.contrib.play.ToJsPathOpsFromJsPath +import play.api.libs.functional.syntax._ +import play.api.libs.json._ + +final case class ApiPartialTrial(hypothesisId: Tristate[UUID], + studyDesignId: Tristate[Long], + overview: Tristate[String], + title: Tristate[String]) { + + def applyTo(orig: Trial): Trial = { + orig.copy( + hypothesisId = hypothesisId.map(UuidId(_)).cata(Some(_), None, orig.hypothesisId), + studyDesignId = studyDesignId.map(LongId(_)).cata(Some(_), None, orig.studyDesignId), + overview = overview.cata(Some(_), None, orig.overview), + title = title.cata(Some(_).getOrElse(""), "", orig.title) + ) + } +} + +object ApiPartialTrial { + + private val reads: Reads[ApiPartialTrial] = ( + (JsPath \ "hypothesisId").readTristate[UUID] and + (JsPath \ "studyDesignId").readTristate[Long] and + (JsPath \ "overview").readTristate[String] and + (JsPath \ "title").readTristate[String] + ) (ApiPartialTrial.apply _) + + private val writes: Writes[ApiPartialTrial] = ( + (JsPath \ "hypothesisId").writeTristate[UUID] and + (JsPath \ "studyDesignId").writeTristate[Long] and + (JsPath \ "overview").writeTristate[String] and + (JsPath \ "title").writeTristate[String] + ) (unlift(ApiPartialTrial.unapply)) + + implicit val format: Format[ApiPartialTrial] = Format(reads, writes) +} |