Last active
August 20, 2017 19:52
-
-
Save jducoeur/16913454548560a77d7d7824d9fb0806 to your computer and use it in GitHub Desktop.
Working Event Controller
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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