Commit 127df582 authored by Tom Käsler's avatar Tom Käsler

Merge branch 'questionCreationForSession' into 'master'

new api endpoint for creating a question for a session

See merge request !16
parents 98ccc651 b2feabfc
Pipeline #7952 passed with stages
in 5 minutes and 22 seconds
......@@ -64,5 +64,28 @@ trait QuestionApi {
}
}
}
} ~
pathPrefix(ApiRoutes.getRoute("session")) {
pathPrefix(IntNumber) { sessionId =>
pathPrefix(ApiRoutes.getRoute("question")) {
pathEndOrSingleSlash {
get {
parameters("variant".?) { variant =>
variant match {
case Some(v) => complete(QuestionService.findQuestionsBySessionIdAndVariant(sessionId, v)
.map(questionAdapter.toResources(_)))
case None => complete {QuestionService.findAllBySessionId(sessionId)
.map(questionAdapter.toResources(_))}
}
}
} ~
post {
entity(as[Question]) { question =>
complete (QuestionService.create(question.copy(sessionId = sessionId)).map(_.toJson))
}
}
}
}
}
}
}
......@@ -121,6 +121,22 @@ trait QuestionApiSpec extends FunSpec with Matchers with ScalaFutures with BaseS
}
}
}
it("create question for session properly") {
val sessionId = 2
val newFreetext = Question(None, 0, "session question", "session question content", "preparation", "freetext",
None, None, true, true, false, true, true, None, None)
val requestEntity = HttpEntity(MediaTypes.`application/json`, newFreetext.toJson.toString)
Post(s"/session/${sessionId}/question", requestEntity) ~> questionApi ~> check {
response.status should be(OK)
val newQuestionId: Future[String] = Unmarshal(response.entity).to[String]
newQuestionId.onSuccess { case newId =>
val checkFreetext = newFreetext.copy(id = Some(newId.toLong), sessionId = sessionId)
Get("/question/" + newId.toString) ~> questionApi ~> check {
responseAs[JsObject] should be(questionAdapter.toResource(checkFreetext.asInstanceOf[Question]))
}
}
}
}
it("update answer options properly") {
val question = preparationQuestions.last
val updatedAnswerOptions: Seq[AnswerOption] = question.answerOptions.get
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment