Commit 64348fe6 authored by Fjen Undso's avatar Fjen Undso
Browse files

controllers: add http error codes as comments

parent 6158f66e
......@@ -26,10 +26,10 @@ public class QuestionController extends Controller {
public static Result createAnswer(String sid) {
Session session = Session.find.byId(sid);
if (session == null) {
return notFound("session not found");
return notFound("session not found"); //404
}
if (!session.open) {
return forbidden("session not open");
return forbidden("session not open"); //403
}
JsonNode json = request().body().asJson();
......@@ -39,9 +39,9 @@ public class QuestionController extends Controller {
answer.answer);
session.addQuestionAnswer(inserted);
session.save();
return created(Json.toJson(inserted));
return created(Json.toJson(inserted)); //201
} else {
return badRequest("owner missing");
return badRequest("owner missing"); //400
}
}
......@@ -55,9 +55,9 @@ public class QuestionController extends Controller {
public static Result getAnswers(String sid) {
Session session = Session.find.byId(sid);
if (session == null) {
return notFound("session not found");
return notFound("session not found"); //404
} else {
return ok(Json.toJson(session.questionAnswers));
return ok(Json.toJson(session.questionAnswers)); //200
}
}
......@@ -73,15 +73,15 @@ public class QuestionController extends Controller {
public static Result resetAnswers(String sid, String owner) {
Session session = Session.find.byId(sid);
if (session == null) {
return notFound("session not found");
return notFound("session not found"); //404
}
if (session.owner.equals(owner)) {
session.resetAnswers();
session.save();
return noContent();
return noContent(); //204
} else {
return forbidden("wrong owner");
return unauthorized("wrong owner"); //401
}
}
}
......@@ -22,7 +22,7 @@ public class SessionController extends Controller {
*/
public static Result getSessions() {
List<Session> sessions = Session.find.all();
return ok(Json.toJson(sessions));
return ok(Json.toJson(sessions)); //200
}
/**
......@@ -35,7 +35,7 @@ public class SessionController extends Controller {
public static Result getSessionsByOwner(String owner) {
List<Session> sessions = Session.findFromOwner(owner);
return sessions.isEmpty() ? notFound("no sessions") : ok(Json
.toJson(sessions));
.toJson(sessions)); //200 or 404
Please register or sign in to reply
}
/**
......@@ -48,7 +48,7 @@ public class SessionController extends Controller {
public static Result getSession(String sid) {
Session session = Session.find.byId(sid);
return session == null ? notFound("session not found") : ok(Json
.toJson(session));
.toJson(session)); //200 or 404
}
/**
......@@ -65,9 +65,9 @@ public class SessionController extends Controller {
Session sessionSaved = new Session(session.owner, session.name,
session.open, session.date);
sessionSaved.save();
return created(Json.toJson(sessionSaved));
return created(Json.toJson(sessionSaved)); //201
} else {
return badRequest("name or owner missing");
return badRequest("name or owner missing"); //400
}
}
......@@ -84,17 +84,17 @@ public class SessionController extends Controller {
Session session = Json.fromJson(json, Session.class);
Session sessionSaved = Session.find.byId(sid);
if (sessionSaved == null) {
return notFound("session not found");
return notFound("session not found"); //404
}
if (!sessionSaved.owner.equals(session.owner)) {
return forbidden("wrong owner");
return unauthorized("wrong owner"); //401
}
sessionSaved.name = session.name;
sessionSaved.date = session.date;
sessionSaved.open = session.open;
sessionSaved.save();
return ok(Json.toJson(sessionSaved));
return ok(Json.toJson(sessionSaved)); //200
}
/**
......@@ -109,14 +109,14 @@ public class SessionController extends Controller {
public static Result deleteSession(String sid, String owner) {
Session session = Session.find.byId(sid);
if (session == null) {
return notFound("session not found");
return notFound("session not found"); //404
}
if (session.owner.equals(owner)) {
session.delete();
return noContent();
return noContent(); //204
} else {
return forbidden("wrong owner");
return unauthorized("wrong owner"); //401
}
}
}
......@@ -25,10 +25,10 @@ public class VoteController extends Controller {
public static Result createVote(String sid) {
Session session = Session.find.byId(sid);
if (session == null) {
return notFound("session not found");
return notFound("session not found"); //404
}
if (!session.open) {
return forbidden("session not open");
return forbidden("session not open"); //403
}
JsonNode json = request().body().asJson();
......@@ -37,9 +37,9 @@ public class VoteController extends Controller {
Vote inserted = new Vote(session, vote.owner, vote.type, vote.vote);
session.addVote(inserted);
session.save();
return created(Json.toJson(inserted));
return created(Json.toJson(inserted)); //201
} else {
return badRequest("owner missing");
return badRequest("owner missing"); //401
}
}
......@@ -53,9 +53,9 @@ public class VoteController extends Controller {
public static Result getVotes(String sid) {
Session session = Session.find.byId(sid);
if (session == null) {
return notFound("session not found");
return notFound("session not found"); //404
} else {
return ok(Json.toJson(session.votes));
return ok(Json.toJson(session.votes)); //200
}
}
}
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