Im writing a backend restful api server in Scala Playframework using Slick for database access.
Because my database schema evolves all the time, I decided to generate Slick helper classes via slick-codegen. The Users table is mapped to this Scala case class
case class UserRow(userId: Long, username: String, passwordHash: String,
passwordSalt: String, email: String, firstName: String, ...)
Now my data access consists of 2 layers: Service & DAO
DAO is very simple and allows inserting, deleting etc UserRow's from and to database
Now my problem starts at the Service layer design invoked by the application controllers.
If e.g it show(id) method would return an UserRow, I would reveal user's private salt and password hash. On the other hand, this approach would allow me to easily wrap them in and out of JSON.
Another way is for the show method (used just as an example) to return a tuple containing the data, but that would be inconvenient for json transfering.
Also, I could create an additional User class but that would create tons of boilerplate in the long run
What is the right way to handle this situation? Where can I find recommended and smart pattern in the future?
Aucun commentaire:
Enregistrer un commentaire