Advertisement
Guest User

Untitled

a guest
Mar 14th, 2016
249
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scala 1.42 KB | None | 0 0
  1. package controllers
  2. import scala.concurrent.Future
  3. import javax.inject.Inject
  4. import play.api.mvc._
  5. import play.api.libs.concurrent.Execution.Implicits.defaultContext
  6. import formats.stateFormat
  7.  
  8. class Sms @Inject() (service: SmsService) extends Controller {
  9.  
  10.   def getState() =
  11.     Action async { request =>
  12.       service map { state =>
  13.         Ok(state)
  14.       }
  15.     }
  16.  
  17. }
  18.  
  19. //-----------------------------------------------------------------------------------------------------------------------
  20.  
  21. package object controllers {
  22.  
  23.   implicit def model2JsonWritable[M](implicit c: Codec, w: Writes[M]) =
  24.     Writeable[M] { m: M => c.encode(Json.stringify(Json.toJson[M](m))) }
  25.  
  26. }
  27.  
  28. //-----------------------------------------------------------------------------------------------------------------------
  29. package services
  30.  
  31. @Singleton
  32. class SmsService {
  33.  
  34.   def getState(): Future[State] =
  35.     Future successful State("Some state")
  36.  
  37. }
  38.  
  39. //-----------------------------------------------------------------------------------------------------------------------
  40. package models
  41.  
  42. case class State(title: String)
  43.  
  44. //-----------------------------------------------------------------------------------------------------------------------
  45. import play.api.libs.json._
  46. import play.api.libs.functional.syntax._
  47.  
  48. package object formats {
  49.  
  50.   val stateFormat =
  51.     (__ \ 'state).format[State](State, unlift(State.unapply))
  52.  
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement