Skip to content

Instantly share code, notes, and snippets.

@letusfly85
Last active March 17, 2018 06:25
Show Gist options
  • Save letusfly85/d9fa0e854ff4cfec9f49186eca08996e to your computer and use it in GitHub Desktop.
Save letusfly85/d9fa0e854ff4cfec9f49186eca08996e to your computer and use it in GitHub Desktop.
sample.scala
/***
*
*
* before
*
*/
def createDefinition = Action { implicit request =>
request.body.asJson match {
case Some(json) =>
Json.fromJson[WorkflowDefinitionEntity](json) match {
case JsSuccess(schemeEntity, _) =>
service.createDefinition(schemeEntity) match {
case Right(_) => Created(Json.toJson(schemeEntity))
case Left(e) =>
Logger.info(e.toString())
InternalServerError(JsObject.empty)
}
case JsError(e) =>
Logger.info(e.toString())
InternalServerError(JsObject.empty)
}
case None =>
InternalServerError(JsObject.empty)
}
}
/***
*
*
* after
*
*/
def createDefinition = Action { implicit request =>
Try {
for {
json <- request.body.asJson.toRight(new Exception("")).right
schemeEntity <- Json.fromJson[WorkflowDefinitionEntity](json).right
entity <- service.createDefinition(schemeEntity).right
} yield entity
} match {
case Success(resultEntity) => resultEntity match {
case Right(entity) => Created(Json.toJson(entity))
case Left(e) => InternalServerError(JsObject.empty)
}
case Failure(_) => InternalServerError(JsObject.empty)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment