I am developing my first Play 2.1 application in Scala. The task I am trying to accomplish is to parse json into 3 different case classes. The problem is - I do not know where to declare all case classes. Each class in it's own file or all in one file. Here is what I've done (it doesn't work, case values are not visible in controller object):
File LoginBase.scala
package models abstract class LoginBase case class Login(email: String, password: String) extends LoginBase case class RestoreLogin(email: String, captchaID: String, captchaAnswer: String) extends LoginBase case class RegisterLogin(email: String, password: String, captchaID: String, captchaAnswer: String) extends LoginBase
File
package controllers import play.api._ import play.api.mvc._ import play.api.data._ import play.api.data.Forms._ import play.api.Play.current import play.api.cache.Cache import play.api.libs.json._ import play.api.mvc._ import play.api.libs.functional.syntax._ import nl.captcha.Captcha import nl.captcha.Captcha._ import nl.captcha.gimpy.FishEyeGimpyRenderer import nl.captcha.text.renderer.ColoredEdgesWordRenderer import nl.captcha.text.renderer.DefaultWordRenderer import nl.captcha.gimpy.DropShadowGimpyRenderer import java.io.ByteArrayOutputStream import javax.imageio.ImageIO import java.util.UUID import play.api.libs.functional.syntax._ import models.LoginBase object LoginActions extends Controller { implicit val loginReads = ( (__ \ "email").read[String] and (__ \ "password").read[String] )(Login.apply _) implicit val restoreLoginReads = ( (__ \ "email").read[String] and (__ \ "captchaID").read[String] and (__ \ "captchaAnswer").read[String] )(RestoreLogin) implicit val registerLoginReads = ( (__ \ "email").read[String] and (__ \ "password").read[String] and (__ \ "captchaID").read[String] and (__ \ "captchaAnswer").read[String] )(RegisterLogin) def registerLogin = Action(parse.json){ /* To be implementd */ } }
If someone can help me with this, I'll appreciate. All I can find is REPL examples, but I am missing some fundamental stuff - where to put all the pieces of code? what is the file structure?
Thanks, Andrei.