aboutsummaryrefslogtreecommitdiff
path: root/src/main/scala/xyz/driver/pdsuidomain/formats/json/document/ApiDocumentType.scala
blob: 8b4974f43178ae7659c0b7e468b55e495431c59b (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
package xyz.driver.pdsuidomain.formats.json.document

import play.api.libs.functional.syntax._
import play.api.libs.json.{Format, JsPath}
import xyz.driver.pdsuicommon.domain.LongId
import xyz.driver.pdsuidomain.entities.DocumentType

final case class ApiDocumentType(id: Long, name: String) {

  def toDomain = DocumentType(
    id = LongId(this.id),
    name = this.name
  )

}

object ApiDocumentType {

  implicit val format: Format[ApiDocumentType] = (
    (JsPath \ "id").format[Long] and
      (JsPath \ "name").format[String]
  )(ApiDocumentType.apply, unlift(ApiDocumentType.unapply))

  def fromDomain(documentType: DocumentType) = ApiDocumentType(
    id = documentType.id.id,
    name = documentType.name
  )
}