aboutsummaryrefslogtreecommitdiff
path: root/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/trialissue.scala
diff options
context:
space:
mode:
authorKseniya Tomskikh <ktomskih@datamonsters.co>2017-08-04 17:57:12 +0600
committerKseniya Tomskikh <ktomskih@datamonsters.co>2017-08-11 14:41:17 +0600
commitef9517e1b8f599fbdd15c474cf7dfea61e803c2f (patch)
treec31a139d35dab0c10c70bb7afef2bca8e48f0fee /src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/trialissue.scala
parent5519c219e2404cb19b6116dee90b40b5e5e2a720 (diff)
downloadrest-query-ef9517e1b8f599fbdd15c474cf7dfea61e803c2f.tar.gz
rest-query-ef9517e1b8f599fbdd15c474cf7dfea61e803c2f.tar.bz2
rest-query-ef9517e1b8f599fbdd15c474cf7dfea61e803c2f.zip
PDSUI-2188 Created and fixed spray json formats for tric and rep
Diffstat (limited to 'src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/trialissue.scala')
-rw-r--r--src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/trialissue.scala60
1 files changed, 60 insertions, 0 deletions
diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/trialissue.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/trialissue.scala
new file mode 100644
index 0000000..572f44d
--- /dev/null
+++ b/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/trialissue.scala
@@ -0,0 +1,60 @@
+package xyz.driver.pdsuidomain.formats.json.sprayformats
+
+import java.time.LocalDateTime
+
+import spray.json._
+import xyz.driver.pdsuicommon.domain.{LongId, StringId, User}
+import xyz.driver.pdsuidomain.entities._
+
+object trialissue {
+ import DefaultJsonProtocol._
+ import common._
+
+ def applyUpdateToTrialIssue(json: JsValue, orig: TrialIssue): TrialIssue = {
+ json.asJsObject.getFields("text", "evidence", "archiveRequired", "meta") match {
+ case Seq(text, evidence, archiveRequired, meta) =>
+ orig.copy(
+ text = text.convertTo[String],
+ evidence = evidence.convertTo[String],
+ archiveRequired = archiveRequired.convertTo[Boolean],
+ meta = meta.convertTo[String]
+ )
+
+ case _ => deserializationError(s"Expected Json Object as partial TrialIssue, but got $json")
+ }
+ }
+
+ def jsValueToTrialIssue(json: JsValue, trialId: StringId[Trial], userId: StringId[User]): TrialIssue = {
+ json.asJsObject.getFields("text", "evidence", "meta") match {
+ case Seq(text, evidence, meta) =>
+ TrialIssue(
+ id = LongId(0),
+ userId = userId,
+ trialId = trialId,
+ lastUpdate = LocalDateTime.MIN,
+ isDraft = true,
+ text = text.convertTo[String],
+ evidence = evidence.convertTo[String],
+ archiveRequired = false,
+ meta = meta.convertTo[String]
+ )
+
+ case _ => deserializationError(s"Expected Json Object as TrialIssue, but got $json")
+ }
+
+ }
+
+ implicit val trialIssueWriter = new JsonWriter[TrialIssue] {
+ override def write(obj: TrialIssue) = JsObject(
+ "id" -> obj.id.toJson,
+ "text" -> obj.text.toJson,
+ "lastUpdate" -> obj.lastUpdate.toJson,
+ "userId" -> obj.userId.toJson,
+ "isDraft" -> obj.isDraft.toJson,
+ "evidence" -> obj.evidence.toJson,
+ "archiveRequired" -> obj.archiveRequired.toJson,
+ "meta" -> obj.meta.toJson
+ )
+ }
+
+}