diff options
Diffstat (limited to 'src/main/scala/xyz/driver/pdsuidomain/formats/json/patientissue/ApiPatientIssue.scala')
-rw-r--r-- | src/main/scala/xyz/driver/pdsuidomain/formats/json/patientissue/ApiPatientIssue.scala | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/patientissue/ApiPatientIssue.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/patientissue/ApiPatientIssue.scala new file mode 100644 index 0000000..7e0b174 --- /dev/null +++ b/src/main/scala/xyz/driver/pdsuidomain/formats/json/patientissue/ApiPatientIssue.scala @@ -0,0 +1,42 @@ +package xyz.driver.pdsuidomain.formats.json.patientissue + +import java.time.{ZoneId, ZonedDateTime} + +import play.api.libs.functional.syntax._ +import play.api.libs.json._ +import xyz.driver.pdsuidomain.entities.PatientIssue + +final case class ApiPatientIssue(id: Long, + text: String, + lastUpdate: ZonedDateTime, + userId: String, + isDraft: Boolean, + evidence: String, + archiveRequired: Boolean, + meta: String) + +object ApiPatientIssue { + implicit val format: Format[ApiPatientIssue] = ( + (JsPath \ "id").format[Long] 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))) + )(ApiPatientIssue.apply, unlift(ApiPatientIssue.unapply)) + + def fromDomain(x: PatientIssue) = ApiPatientIssue( + id = x.id.id, + 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 + ) +} |