Skip to content

Instantly share code, notes, and snippets.

@jducoeur
Last active August 20, 2017 19:52
Show Gist options
  • Save jducoeur/16913454548560a77d7d7824d9fb0806 to your computer and use it in GitHub Desktop.
Save jducoeur/16913454548560a77d7d7824d9fb0806 to your computer and use it in GitHub Desktop.
Working Event Controller
package controllers
import scala.concurrent.Future
import javax.inject._
import play.api.libs.json._
import play.api.mvc._
import scala.concurrent.{ExecutionContext, Future}
import play.api.libs.functional.syntax._
case class Event(id: Long, eventTypeID: Int, title: String, message: String, date: String, featuredImage: String, coordinates: String)
/**
* PURE EXPERIMENT -- please ignore
*/
class EventController @Inject()(cc: ControllerComponents)
(implicit ec: ExecutionContext)extends AbstractController(cc) {
implicit val eventWriter = new Writes[Event] {
def writes(events:Event) = Json.obj(
"id" -> events.id,
"type" -> events.eventTypeID,
"title" -> events.title,
"message" -> events.message,
"featuredImage" -> events.featuredImage,
"date" -> events.date,
"coordinates" -> events.coordinates
)
}
def index = Action.async {
val anEvent = Event(1,2,"Daniel","Daniel","12" ,"737bds","hsjds")
val oneEvent = Json.toJson(anEvent)
val eventSeq = List(anEvent)
val someEvents = Json.toJson(eventSeq)
Future.successful(Ok(""))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment