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

Controllers: add javadoc

parent 9ed60f4a
......@@ -11,6 +11,7 @@ public class Global extends GlobalSettings {
Logger.info("Application has started");
// Check if the database is empty
if (Session.find.findRowCount() == 0) {
// Fill database with sample data
List list = (List) Yaml.load("test-data.yml");
Ebean.save(list);
}
......
......@@ -9,8 +9,19 @@ import play.mvc.Result;
import com.fasterxml.jackson.databind.JsonNode;
/**
* Provides REST API calls for {@link QuestionAnswer} creation
*/
public class QuestionController extends Controller {
/**
* Creates a new {@link QuestionAnswer} for a {@link Session} from the
* request body
*
* @param sid
* the ID of a Session
* @return the QuestionAnswer
*/
@BodyParser.Of(BodyParser.Json.class)
public static Result createAnswer(String sid) {
Session session = Session.find.byId(sid);
......
......@@ -10,25 +10,53 @@ import play.mvc.Result;
import com.fasterxml.jackson.databind.JsonNode;
/**
* Provides REST API calls for session listing and creation
*/
public class SessionController extends Controller {
/**
* Gets details of all {@link Session}s
*
* @return list of all Sessions
*/
public static Result getSessions() {
List<Session> sessions = Session.find.all();
return ok(Json.toJson(sessions));
}
/**
* Get details of all {@link Session}s from one owner
*
* @param owner
* the owner of the Sessions
* @return list of all Sessions from a specified owner
*/
public static Result getSessionsByOwner(String owner) {
List<Session> sessions = Session.findFromOwner(owner);
return sessions.isEmpty() ? notFound("no sessions") : ok(Json
.toJson(sessions));
}
/**
* Get details of a specified {@link Session}
*
* @param sid
* the ID of a Session
* @return the Session
*/
public static Result getSession(String sid) {
Session session = Session.find.byId(sid);
return session == null ? notFound("session not found") : ok(Json
.toJson(session));
}
/**
* Creates a new {@link Session} from the provided information in the
* request body
*
* @return the new Session
*/
@BodyParser.Of(BodyParser.Json.class)
public static Result createSession() {
JsonNode json = request().body().asJson();
......@@ -43,6 +71,13 @@ public class SessionController extends Controller {
}
}
/**
* Updates the details of a specified {@link Session}
*
* @param sid
* the ID of a Session
* @return the Session
*/
@BodyParser.Of(BodyParser.Json.class)
public static Result updateSession(String sid) {
JsonNode json = request().body().asJson();
......@@ -62,6 +97,15 @@ public class SessionController extends Controller {
return ok(Json.toJson(sessionSaved));
}
/**
* Deletes a {@link Session}
*
* @param sid
* the ID of a Session
* @param owner
* the owner of the Session
* @return HTTP 204 if deleted
*/
public static Result deleteSession(String sid, String owner) {
Session session = Session.find.byId(sid);
if (session == null) {
......@@ -76,6 +120,13 @@ public class SessionController extends Controller {
}
}
/**
* 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) {
......@@ -85,6 +136,13 @@ public class SessionController extends Controller {
}
}
/**
* 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) {
......@@ -94,6 +152,15 @@ public class SessionController extends Controller {
}
}
/**
* 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) {
......
......@@ -9,8 +9,18 @@ import play.mvc.Result;
import com.fasterxml.jackson.databind.JsonNode;
/**
* Provides REST API calls for {@link Vote} creation
*/
public class VoteController extends Controller {
/**
* Creates a new {@link Vote} for a {@link Session} from the request body
*
* @param sid
* the ID of a Session
* @return the Vote
*/
@BodyParser.Of(BodyParser.Json.class)
public static Result createVote(String sid) {
Session session = Session.find.byId(sid);
......
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