Commit 6158f66e authored by Fjen Undso's avatar Fjen Undso
Browse files

move all vote/question specific code to the right controller

parent 7aaddaa0
......@@ -44,4 +44,44 @@ public class QuestionController extends Controller {
return badRequest("owner missing");
}
}
/**
* Gets all {@link QuestionAnswer}s for a {@link Session}
*
* @param sid
* the ID of a Session
* @return list of QuestionAnswers
*/
public static Result getAnswers(String sid) {
Session session = Session.find.byId(sid);
if (session == null) {
return notFound("session not found");
} else {
return ok(Json.toJson(session.questionAnswers));
}
}
/**
* Deletes all {@link QuestionAnswer}s from a {@link Session}
*
* @param sid
* the ID of a Session
* @param owner
* the owner of the Session
* @return HTTP 204 if reseted
*/
public static Result resetAnswers(String sid, String owner) {
Session session = Session.find.byId(sid);
if (session == null) {
return notFound("session not found");
}
if (session.owner.equals(owner)) {
session.resetAnswers();
session.save();
return noContent();
} else {
return forbidden("wrong owner");
}
}
}
......@@ -2,9 +2,7 @@ package controllers;
import java.util.List;
import models.QuestionAnswer;
import models.Session;
import models.Vote;
import play.libs.Json;
import play.mvc.BodyParser;
import play.mvc.Controller;
......@@ -121,60 +119,4 @@ public class SessionController extends Controller {
return forbidden("wrong owner");
}
}
/**
* Gets all {@link Vote}s for a {@link Session}
*
* @param sid
* the ID of a Session
* @return list of Votes
*/
public static Result getVotes(String sid) {
Session session = Session.find.byId(sid);
if (session == null) {
return notFound("session not found");
} else {
return ok(Json.toJson(session.votes));
}
}
/**
* Gets all {@link QuestionAnswer}s for a {@link Session}
*
* @param sid
* the ID of a Session
* @return list of QuestionAnswers
*/
public static Result getAnswers(String sid) {
Session session = Session.find.byId(sid);
if (session == null) {
return notFound("session not found");
} else {
return ok(Json.toJson(session.questionAnswers));
}
}
/**
* Deletes all {@link QuestionAnswer}s from a {@link Session}
*
* @param sid
* the ID of a Session
* @param owner
* the owner of the Session
* @return HTTP 204 if reseted
*/
public static Result resetAnswers(String sid, String owner) {
Session session = Session.find.byId(sid);
if (session == null) {
return notFound("session not found");
}
if (session.owner.equals(owner)) {
session.resetAnswers();
session.save();
return noContent();
} else {
return forbidden("wrong owner");
}
}
}
\ No newline at end of file
}
......@@ -42,4 +42,20 @@ public class VoteController extends Controller {
return badRequest("owner missing");
}
}
/**
* Gets all {@link Vote}s for a {@link Session}
*
* @param sid
* the ID of a Session
* @return list of Votes
*/
public static Result getVotes(String sid) {
Session session = Session.find.byId(sid);
if (session == null) {
return notFound("session not found");
} else {
return ok(Json.toJson(session.votes));
}
}
}
......@@ -9,14 +9,13 @@ GET /sessions/:sid controllers.SessionController.getSession(si
POST /sessions controllers.SessionController.createSession
PUT /sessions/:sid controllers.SessionController.updateSession(sid: String)
DELETE /sessions/:sid/:owner controllers.SessionController.deleteSession(sid: String, owner: String)
GET /sessions/:sid/votes controllers.SessionController.getVotes(sid: String)
GET /sessions/:sid/answers controllers.SessionController.getAnswers(sid: String)
POST /sessions/:sid/resetanswers/:owner controllers.SessionController.resetAnswers(sid: String, owner: String)
# TODO: aggregierte daten abfragen
# Questionsanswer
POST /answers/:sid controllers.QuestionController.createAnswer(sid: String)
GET /sessions/:sid/answers controllers.QuestionController.getAnswers(sid: String)
POST /sessions/:sid/answers controllers.QuestionController.createAnswer(sid: String)
POST /sessions/:sid/resetanswers/:owner controllers.QuestionController.resetAnswers(sid: String, owner: String)
# Vote
POST /votes/:sid controllers.VoteController.createVote(sid: String)
GET /sessions/:sid/votes controllers.VoteController.getVotes(sid: String)
POST /sessions/:sid/votes controllers.VoteController.createVote(sid: String)
# TODO: aggregierte daten abfragen
\ No newline at end of file
......@@ -24,7 +24,9 @@ import com.avaje.ebean.EbeanServer;
import com.avaje.ebeaninternal.server.ddl.DdlGenerator;
import com.fasterxml.jackson.databind.JsonNode;
import controllers.QuestionController;
import controllers.SessionController;
import controllers.VoteController;
public class ControllerTest {
public static FakeApplication app;
......@@ -124,7 +126,7 @@ public class ControllerTest {
s1.save();
s2.save();
Result result = SessionController.getVotes(s1.id);
Result result = VoteController.getVotes(s1.id);
assertEquals(OK, status(result));
assertEquals("application/json", contentType(result));
......@@ -150,7 +152,7 @@ public class ControllerTest {
s1.save();
s2.save();
Result result = SessionController.getAnswers(s1.id);
Result result = QuestionController.getAnswers(s1.id);
assertEquals(OK, status(result));
assertEquals("application/json", contentType(result));
......
Supports Markdown
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