Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def search = Action(parse.json) { request =>
- val sR = request.body.validate[SearchRequest]
- sR.fold(
- errors => {
- BadRequest(Json.obj("status" -> "KO", "message" -> JsError.toJson(errors)))
- },
- searchRequest => {
- Logger.debug(s"searchRequest is $searchRequest")
- val sr = SearchResults(10)
- Ok(Json.toJson(sr))
- }
- )
- }
- IsGreaThan
- IsLessThan
- EqualTo
- case class SearchRequest(operator: String)
- object SearchOperator extends Enumeration {
- type SearchOperator = Value
- val IsGreaThan = Value("IsGreaThan")
- val IsLessThan = Value("IsLessThan")
- val EqualTo = Value("EqualTo")
- }
- case class SearchRequest(lhs: Int, operator: SearchOperator, rhs:Int)
- object SearchRequestJson {
- implicit val soReads = Reads.enumNameReads(SearchOperator)
- implicit val srReads = Json.reads[SearchRequest]
- }
- { "lhs": 42, "operator": "NotEqualTo", "rhs": 44 }
- JsError(
- List(
- (/operator, List(
- ValidationError(
- List(error.expected.enumstring),
- WrappedArray()
- )
- ))
- )
- )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement