Currently I have a method that accept ModelA
and know to perform actions on it.
so in my controller I accept request of ModelA
and call this method with it.
And now, I want to be able to accept request of ModelB
, map the request to be of ModelA
(cause it has the same data just not all of it and in different names), and call this method with it.
lets say the method would look like:
def myMethod(data: ModelA): ResModel = {
// do something with data
}
my controller currrently would be:
def doActions(): Action[JValue] = { request =>
val dataExctracted = request.body.extract[ModelA]
myMethod(dataExctracted)
...
}
and both of my models are just case classes in seperate files:
case class ModelA(a: String, b: String, c: String)
case class ModelB(aAsDifferentName: String, bAsDifferntName: String)
What would be the best practice of Scala to have the myMethod accept both Models (without Either
) ? and how the controller should look like in reaction to that?
is there also a classic way to return different models without having to accept the calls in different controller methods?
Thanks!