aboutsummaryrefslogtreecommitdiff
path: root/src/main/scala/xyz/driver/pdsuidomain/formats/json/documentissue/ApiDocumentIssue.scala
blob: fab2546d1ceb44227dc371d9814c0d06dbeb9b90 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package xyz.driver.pdsuidomain.formats.json.documentissue

import java.time.{ZoneId, ZonedDateTime}

import play.api.libs.functional.syntax._
import play.api.libs.json._
import xyz.driver.pdsuidomain.entities.DocumentIssue

final case class ApiDocumentIssue(id: Long,
                                  startPage: Option[Double],
                                  endPage: Option[Double],
                                  text: String,
                                  lastUpdate: ZonedDateTime,
                                  userId: String,
                                  isDraft: Boolean,
                                  evidence: String,
                                  archiveRequired: Boolean,
                                  meta: String)

object ApiDocumentIssue {
  implicit val format: Format[ApiDocumentIssue] = (
    (JsPath \ "id").format[Long] and
      (JsPath \ "startPage").formatNullable[Double] and
      (JsPath \ "endPage").formatNullable[Double] and
      (JsPath \ "text").format[String] and
      (JsPath \ "lastUpdate").format[ZonedDateTime] and
      (JsPath \ "userId").format[String] and
      (JsPath \ "isDraft").format[Boolean] and
      (JsPath \ "evidence").format[String] and
      (JsPath \ "archiveRequired").format[Boolean] and
      (JsPath \ "meta").format[String](Format(Reads { x =>
        JsSuccess(Json.stringify(x))
      }, Writes[String](Json.parse)))
  )(ApiDocumentIssue.apply, unlift(ApiDocumentIssue.unapply))

  def fromDomain(x: DocumentIssue) = ApiDocumentIssue(
    id = x.id.id,
    startPage = x.startPage,
    endPage = x.endPage,
    text = x.text,
    lastUpdate = ZonedDateTime.of(x.lastUpdate, ZoneId.of("Z")),
    userId = x.userId.id,
    isDraft = x.isDraft,
    evidence = x.evidence,
    archiveRequired = x.archiveRequired,
    meta = x.meta
  )
}