Commit 71980800 authored by Fjen Undso's avatar Fjen Undso
Browse files

implement question and votecontroller

parent 19573385
package controllers;
import play.mvc.Result;
import models.QuestionAnswer;
import models.Session;
import models.Vote;
import play.libs.Json;
import play.mvc.Controller;
import play.mvc.Result;
public class QuestionController extends Controller {
public static Result createAnswer(String sid) {
return null;
Session session = Session.find.byId(sid);
if (session != null) {
QuestionAnswer answer = Json.fromJson(request().body().asJson(),
QuestionAnswer.class);
if (!answer.owner.isEmpty()) {
QuestionAnswer inserted = new QuestionAnswer(session,
answer.owner, answer.answer);
inserted.save();
return created(Json.toJson(inserted));
} else {
return badRequest("owner missing");
}
} else {
return notFound("session not found");
}
}
}
......@@ -47,7 +47,7 @@ public class SessionController extends Controller {
sessionSaved.name = session.name;
sessionSaved.date = session.date;
sessionSaved.save();
return ok();
return noContent();
} else {
return forbidden("wrong owner");
}
......@@ -61,7 +61,7 @@ public class SessionController extends Controller {
if (session != null) {
if (session.owner == owner) {
session.delete();
return ok();
return noContent();
} else {
return forbidden("wrong owner");
}
......@@ -94,7 +94,7 @@ public class SessionController extends Controller {
if (session.owner == owner) {
session.resetAnswers();
session.save();
return ok();
return noContent();
} else {
return forbidden("wrong owner");
}
......
package controllers;
import play.mvc.Result;
import models.Session;
import models.Vote;
import play.libs.Json;
import play.mvc.Controller;
import play.mvc.Result;
public class VoteController extends Controller {
public static Result createVote(String sid) {
return null;
Session session = Session.find.byId(sid);
if (session != null) {
Vote vote = Json.fromJson(request().body().asJson(), Vote.class);
if (!vote.owner.isEmpty()) {
Vote inserted = new Vote(session, vote.owner, vote.type,
vote.vote);
inserted.save();
return created(Json.toJson(inserted));
} else {
return badRequest("owner missing");
}
} else {
return notFound("session not found");
}
}
}
......@@ -4,7 +4,7 @@
# Session
GET /sessions controllers.SessionController.getSessions
GET /sessions/byowner/:owner controllers.SessionController.getSessionsByOwner(owner: String)
GET /sessions/from/:owner controllers.SessionController.getSessionsByOwner(owner: String)
GET /sessions/:sid controllers.SessionController.getSession(sid: String)
POST /sessions controllers.SessionController.createSession
PUT /sessions/:sid controllers.SessionController.updateSession(sid: String)
......
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