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/message/ApiMessage.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/message/ApiMessage.scala')
-rw-r--r-- | src/main/scala/xyz/driver/pdsuidomain/formats/json/message/ApiMessage.scala | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/message/ApiMessage.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/message/ApiMessage.scala new file mode 100644 index 0000000..20b2607 --- /dev/null +++ b/src/main/scala/xyz/driver/pdsuidomain/formats/json/message/ApiMessage.scala @@ -0,0 +1,59 @@ +package xyz.driver.pdsuidomain.formats.json.message + +import java.time.{ZoneId, ZonedDateTime} + +import play.api.libs.functional.syntax._ +import play.api.libs.json.{Format, JsPath} +import xyz.driver.pdsuidomain.entities.Message + +final case class ApiMessage(id: Long, + text: String, + lastUpdate: ZonedDateTime, + userId: Long, + isDraft: Boolean, + recordId: Option[Long], + documentId: Option[Long], + patientId: Option[String], + trialId: Option[String], + startPage: Option[Double], + endPage: Option[Double], + evidence: Option[String], + archiveRequired: Option[Boolean], + meta: Option[String]) + +object ApiMessage { + + def fromDomain(domain: Message) = ApiMessage( + id = domain.id.id, + text = domain.text, + lastUpdate = ZonedDateTime.of(domain.lastUpdate, ZoneId.of("Z")), + userId = domain.userId.id, + isDraft = domain.isDraft, + recordId = domain.recordId.map(_.id), + documentId = domain.documentId.map(_.id), + patientId = domain.patientId.map(_.toString), + trialId = domain.trialId.map(_.toString), + startPage = domain.startPage, + endPage = domain.endPage, + evidence = domain.evidence, + archiveRequired = domain.archiveRequired, + meta = domain.meta + ) + + implicit val format: Format[ApiMessage] = ( + (JsPath \ "id").format[Long] and + (JsPath \ "text").format[String] and + (JsPath \ "lastUpdate").format[ZonedDateTime] and + (JsPath \ "userId").format[Long] and + (JsPath \ "isDraft").format[Boolean] and + (JsPath \ "recordId").formatNullable[Long] and + (JsPath \ "documentId").formatNullable[Long] and + (JsPath \ "patientId").formatNullable[String] and + (JsPath \ "trialId").formatNullable[String] and + (JsPath \ "startPage").formatNullable[Double] and + (JsPath \ "endPage").formatNullable[Double] and + (JsPath \ "evidence").formatNullable[String] and + (JsPath \ "archiveRequired").formatNullable[Boolean] and + (JsPath \ "meta").formatNullable[String] + ) (ApiMessage.apply, unlift(ApiMessage.unapply)) +} |