aboutsummaryrefslogtreecommitdiff
path: root/src/main/scala/xyz/driver/pdsuidomain/formats/json/documentissue.scala
diff options
context:
space:
mode:
authorKseniya Tomskikh <ktomskih@datamonsters.co>2017-10-20 16:25:04 +0700
committerKseniya Tomskikh <ktomskih@datamonsters.co>2017-10-20 16:25:04 +0700
commit54b15dae509212f6661dc1f1bc4ca248cb487443 (patch)
tree85b1ceafd9a56da511513797bd263977f52b556c /src/main/scala/xyz/driver/pdsuidomain/formats/json/documentissue.scala
parent6d6e732368e97e319653f00e498189afceeb4671 (diff)
downloadrest-query-54b15dae509212f6661dc1f1bc4ca248cb487443.tar.gz
rest-query-54b15dae509212f6661dc1f1bc4ca248cb487443.tar.bz2
rest-query-54b15dae509212f6661dc1f1bc4ca248cb487443.zip
PDSUI-2336 Deleted api classes of play format, userhistory and message services
Diffstat (limited to 'src/main/scala/xyz/driver/pdsuidomain/formats/json/documentissue.scala')
-rw-r--r--src/main/scala/xyz/driver/pdsuidomain/formats/json/documentissue.scala66
1 files changed, 66 insertions, 0 deletions
diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/documentissue.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/documentissue.scala
new file mode 100644
index 0000000..082fa83
--- /dev/null
+++ b/src/main/scala/xyz/driver/pdsuidomain/formats/json/documentissue.scala
@@ -0,0 +1,66 @@
+package xyz.driver.pdsuidomain.formats.json
+
+import java.time.LocalDateTime
+
+import spray.json._
+import xyz.driver.pdsuicommon.domain.{LongId, StringId, User}
+import xyz.driver.pdsuidomain.entities._
+
+object documentissue {
+ import DefaultJsonProtocol._
+ import common._
+
+ def applyUpdateToDocumentIssue(json: JsValue, orig: DocumentIssue): DocumentIssue = json match {
+ case JsObject(fields) =>
+ val text = fields
+ .get("text")
+ .map(_.convertTo[String])
+ .getOrElse(deserializationError(s"DocumentIssue json object does not contain `text` field: $json"))
+
+ val archiveRequired = fields
+ .get("archiveRequired")
+ .map(_.convertTo[Boolean])
+ .getOrElse(deserializationError(s"DocumentIssue json object does not contain `archiveRequired` field: $json"))
+
+ val startPage = fields.get("startPage").map(_.convertTo[Double])
+ val endPage = fields.get("endPage").map(_.convertTo[Double])
+
+ orig.copy(
+ text = text,
+ archiveRequired = archiveRequired,
+ startPage = startPage,
+ endPage = endPage
+ )
+
+ case _ => deserializationError(s"Expected Json Object as partial DocumentIssue, but got $json")
+
+ }
+
+ def jsValueToDocumentIssue(json: JsValue, documentId: LongId[Document], userId: StringId[User]): DocumentIssue =
+ json match {
+ case JsObject(fields) =>
+ val text = fields
+ .get("text")
+ .map(_.convertTo[String])
+ .getOrElse(deserializationError(s"DocumentIssue json object does not contain `text` field: $json"))
+
+ val startPage = fields.get("startPage").map(_.convertTo[Double])
+ val endPage = fields.get("endPage").map(_.convertTo[Double])
+ DocumentIssue(
+ id = LongId(0),
+ userId = userId,
+ documentId = documentId,
+ lastUpdate = LocalDateTime.MIN,
+ isDraft = true,
+ text = text,
+ archiveRequired = false,
+ startPage = startPage,
+ endPage = endPage
+ )
+
+ case _ => deserializationError(s"Expected Json Object as DocumentIssue, but got $json")
+ }
+
+ implicit val documentIssueFormat: RootJsonFormat[DocumentIssue] = jsonFormat9(DocumentIssue.apply)
+
+}