Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package controllers
- import scala.concurrent.Future
- import javax.inject.Inject
- import play.api.mvc._
- import play.api.libs.concurrent.Execution.Implicits.defaultContext
- import formats.stateFormat
- class Sms @Inject() (service: SmsService) extends Controller {
- def getState() =
- Action async { request =>
- service map { state =>
- Ok(state)
- }
- }
- }
- //-----------------------------------------------------------------------------------------------------------------------
- package object controllers {
- implicit def model2JsonWritable[M](implicit c: Codec, w: Writes[M]) =
- Writeable[M] { m: M => c.encode(Json.stringify(Json.toJson[M](m))) }
- }
- //-----------------------------------------------------------------------------------------------------------------------
- package services
- @Singleton
- class SmsService {
- def getState(): Future[State] =
- Future successful State("Some state")
- }
- //-----------------------------------------------------------------------------------------------------------------------
- package models
- case class State(title: String)
- //-----------------------------------------------------------------------------------------------------------------------
- import play.api.libs.json._
- import play.api.libs.functional.syntax._
- package object formats {
- val stateFormat =
- (__ \ 'state).format[State](State, unlift(State.unapply))
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement