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

add stub controllers and rework models

parent bc8e98bc
package controllers;
import play.mvc.Result;
import play.mvc.Controller;
public class QuestionController extends Controller {
public static Result createAnswer(String sid) {
return null;
}
}
package controllers;
import play.mvc.Result;
import play.mvc.Controller;
public class SessionController extends Controller {
}
public static Result getSessions(String owner) {
return null;
}
public static Result getSession(String sid) {
return null;
}
public static Result createSession() {
return null;
}
public static Result updateSession(String sid) {
return null;
}
public static Result deleteSession(String sid, String owner) {
return null;
}
public static Result getVotes(String sid) {
return null;
}
public static Result getAnswers(String sid) {
return null;
}
public static Result resetAnswers(String sid, String owner) {
return null;
}
}
\ No newline at end of file
package controllers;
import play.mvc.Result;
import play.mvc.Controller;
public class VoteController extends Controller {
public static Result createVote(String sid) {
return null;
}
}
package models;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import play.data.format.Formats;
import play.data.validation.Constraints;
import play.db.ebean.Model;
@Entity
public class Question extends Model {
@Id
public String id;
@ManyToOne
@Constraints.Required
public Session session;
@Constraints.Required
public String question;
@Formats.DateTime(pattern = "yyyy-MM-dd HH:mm:ss")
public Date date = new Date();
public Boolean open;
@OneToMany(mappedBy = "question", cascade = CascadeType.ALL)
@Column(nullable = true)
public List<QuestionAnswer> answers = new ArrayList<>();
public static Finder find = new Finder(Long.class, Question.class);
public Question(Session session, String question) {
this.session = session;
this.question = question;
}
}
......@@ -20,7 +20,7 @@ public class QuestionAnswer extends Model {
@ManyToOne
@Constraints.Required
public Question question;
public Session session;
@Constraints.Required
public String owner;
......@@ -47,8 +47,8 @@ public class QuestionAnswer extends Model {
public static Finder find = new Finder(Long.class, QuestionAnswer.class);
public QuestionAnswer(Question question, String owner, Answer answer) {
this.question = question;
public QuestionAnswer(Session session, String owner, Answer answer) {
this.session = session;
this.owner = owner;
this.answer = answer;
}
......
......@@ -36,9 +36,12 @@ public class Session extends Model {
@Column(nullable = true)
public List<Vote> votes = new ArrayList<>();
@Formats.DateTime(pattern = "yyyy-MM-dd HH:mm:ss")
public Date resetDate = new Date();
@OneToMany(mappedBy = "session", cascade = CascadeType.ALL)
@Column(nullable = true)
public List<Question> questions = new ArrayList<>();
public List<QuestionAnswer> questionAnswers = new ArrayList<>();
public static Finder find = new Finder(Long.class, Session.class);
......@@ -47,4 +50,11 @@ public class Session extends Model {
this.name = name;
this.open = true;
}
public void resetAnswers() {
this.date = new Date();
for (QuestionAnswer a: this.questionAnswers) {
a.delete();
}
}
}
......@@ -44,6 +44,9 @@ public class Vote extends Model {
@EnumValue("R")
REQUEST,
@EnumValue("N")
NOREQUEST,
}
public static Finder find = new Finder(Long.class, Vote.class);
......
......@@ -3,22 +3,19 @@
# ~~~~
# Session
GET /sessions controllers.SessionController.getSessions
GET /sessions/:id controllers.SessionController.getSession(id: String)
POST /sessions controllers.SessionController.createSession
PUT /sessions/:id controllers.SessionController.updateSession(id: String)
DELETE /sessions/:id/:owner controllers.SessionController.deleteSession(id: String, owner: String)
GET /sessions/:id/votes controllers.SessionController.getVotes(id: String)
GET /sessions/:id/questions controllers.SessionController.getQuestions(id: String)
GET /sessions/byowner/:owner controllers.SessionController.getSessions(owner: String)
GET /sessions/:sid controllers.SessionController.getSession(sid: String)
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)
# Question
GET /questions/:id controllers.QuestionController.getQuestion(id: String)
POST /questions/:id controllers.QuestionController.createQuestion(id: String)
PUT /questions/:id controllers.QuestionController.updateQuestion(id: String)
DELETE /questions/:id/:owner controllers.QuestionController.deleteQuestion(id: String, owner: String)
# TODO: aggregierte daten abfragen
GET /questions/:id/answers controllers.QuestionController.getAnswers(id: String)
POST /questions/:id/answers controllers.QuestionController.createAnswer(id: String)
# Questionsanswer
POST /answers/:sid controllers.QuestionController.createAnswer(sid: String)
# Vote
POST /votes/:id controllers.VoteController.createVote(id: String)
\ No newline at end of file
POST /votes/:sid controllers.VoteController.createVote(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