diff options
author | vlad <vlad@driver.xyz> | 2018-01-25 14:12:31 -0800 |
---|---|---|
committer | vlad <vlad@driver.xyz> | 2018-01-25 14:12:31 -0800 |
commit | a0877d81ca2844d75dc361b5ce7c99afacd6e25f (patch) | |
tree | 8fe49f45cbcddbbb9a3d167099abe7aa2625e56b /src/main/scala/xyz/driver/pdsuidomain/formats/json/documentissue.scala | |
parent | 46a22e9ab324a0068a85952cdc809800f360f445 (diff) | |
download | rest-query-a0877d81ca2844d75dc361b5ce7c99afacd6e25f.tar.gz rest-query-a0877d81ca2844d75dc361b5ce7c99afacd6e25f.tar.bz2 rest-query-a0877d81ca2844d75dc361b5ce7c99afacd6e25f.zip |
Extracting query library
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.scala | 72 |
1 files changed, 0 insertions, 72 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 deleted file mode 100644 index 037a3ad..0000000 --- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/documentissue.scala +++ /dev/null @@ -1,72 +0,0 @@ -package xyz.driver.pdsuidomain.formats.json - -import java.time.LocalDateTime - -import spray.json._ -import xyz.driver.core.auth.User -import xyz.driver.core.json._ -import xyz.driver.pdsuicommon.domain.LongId -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[Option[Double]]) - val endPage = fields.get("endPage").map(_.convertTo[Option[Double]]) - - orig.copy( - text = text, - archiveRequired = archiveRequired, - startPage = startPage.getOrElse(orig.startPage), - endPage = endPage.getOrElse(orig.endPage) - ) - - case _ => deserializationError(s"Expected Json Object as partial DocumentIssue, but got $json") - - } - - def jsValueToDocumentIssue(json: JsValue, - documentId: LongId[Document], - userId: xyz.driver.core.Id[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 id = fields.get("id").map(_.convertTo[LongId[DocumentIssue]]) - val startPage = fields.get("startPage").flatMap(_.convertTo[Option[Double]]) - val endPage = fields.get("endPage").flatMap(_.convertTo[Option[Double]]) - - DocumentIssue( - id = id.getOrElse(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) - -} |