我试图不仅清理这段代码,而且在request.body isEmpty
时它会破坏,这会破坏这段代码的目的。我一直在参考Play的文档来实现getOrElse
,但我很难看到如何将我的代码段转换为他们提供的内容。这是方法:
override def createWOTC(clientID: Int) =
Action(parse.json) { implicit request =>
val partnerID = {
if ((request.body \ "partner_id").as[String].isEmpty) "jobapp"
else (request.body \ "partner_id").as[String]
}
val partnerAuth = {
if ((request.body \ "partner_auth").as[String].isEmpty) "(snip)"
else (request.body \ "partner_auth").as[String]
}
val handshakeURL = {
if ((request.body \ "handshake_url").as[String].isEmpty) "(snip)"
else (request.body \ "handshake_url").as[String]
}
...
wotcService.createWOTC(clientID, (request.body \ "company").as[String], (request.body \ "auth").as[String],
partnerID, partnerAuth, handshakeURL, eligibilityURL, hireURL, pdfURL)
NoContent
}
答案 0 :(得分:2)
val partnerAuth = (request.body \ "partner_auth").asOpt[String].getOrElse("SxtWJbboccljiaii")