Last active
March 17, 2018 06:25
-
-
Save letusfly85/d9fa0e854ff4cfec9f49186eca08996e to your computer and use it in GitHub Desktop.
sample.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*** | |
* | |
* | |
* 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