ChoiceAnswerApi.scala 673 Bytes
Newer Older
Tom Käsler's avatar
Tom Käsler committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
package api

import services.AnswerService

import scala.concurrent.ExecutionContext.Implicits.global
import akka.http.scaladsl.marshallers.sprayjson.SprayJsonSupport._
import models._
import akka.http.scaladsl.server.Directives._
import spray.json._

trait ChoiceAnswerApi {
  import mappings.ChoiceAnswerJsonProtocol._

  val choiceAnswerApi = pathPrefix("question") {
    pathPrefix(IntNumber) { id =>
      pathPrefix("choiceAnswer") {
        pathEndOrSingleSlash {
          post {
            entity(as[ChoiceAnswer]) { answer =>
              complete (AnswerService.createChoiceAnswer(answer).map(_.toJson))
            }
          }
        }
      }
    }
  }
}