Alright... so after a long break I finally got somewhere. Someone please correct me if I am wrong but it seems to me that if I create an object
case class User(
uuid: Option[UUID],
name: String,
nickname: Option[String],
birthday: Double,
dateCreated: Option[Double],
dateUpdated: Option[Double]
) {}
to quote the play documentation: The Play JSON API provides implicit Writes
for most basic types, such as Int
,Double
, String
, and Boolean
.
The model acts like a validation or is used as validation by the json library.
This partially answers my question.
Now I'm trying to figure out how I can add certain data like date_created to the response. and then return an object together with a 201 or a 200.
def create = Action.async(parse.json) { implicit request =>
validateAndThen[E] {
entity =>
service.create(entity).map {
case Right(id) => Created(Json.toJson(entity)).withHeaders(LOCATION -> redirectUrl(id).url)
case Left(err) => BadRequest(err)
}
}
}
so I can return the entity created with the response but I want to generate the creation date and update date...
any idea on how best to do this?
Best Regards,
Stevenson Lee