Commit 3e32cd0e authored by Fjen Undso's avatar Fjen Undso
Browse files

fix vote and questionanswer deletion

parent 0ecb019f
......@@ -47,13 +47,13 @@ public class VoteController extends Controller {
// session owner has the power to reset all
for (Vote v : session.votes) {
if (v.type == Vote.Type.REQUEST && v.owner == vote.owner || vote.owner == session.owner) {
v.delete();
session.deleteVote(v);
}
}
} else {
session.addVote(inserted);
session.save();
}
session.save();
return created(Json.toJson(inserted)); // 201
} else {
return badRequest("owner missing"); // 400
......
......@@ -42,7 +42,6 @@ public class Session extends Model {
@JsonIgnore
@OneToMany(mappedBy = "session", cascade = CascadeType.ALL)
@Column(nullable = true)
public List<Vote> votes = new ArrayList<Vote>();
@Formats.DateTime(pattern = "yyyy-MM-dd HH:mm:ss")
......@@ -86,6 +85,12 @@ public class Session extends Model {
for (QuestionAnswer a : this.questionAnswers) {
a.delete();
}
this.questionAnswers.clear();
}
public void deleteVote(Vote v) {
v.delete();
this.votes.remove(v);
}
public void addVote(Vote v) {
......
......@@ -8,13 +8,13 @@ import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import com.avaje.ebean.annotation.EnumValue;
import com.fasterxml.jackson.annotation.JsonIgnore;
import play.data.format.Formats;
import play.data.validation.Constraints;
import play.db.ebean.Model;
import com.avaje.ebean.annotation.EnumValue;
import com.fasterxml.jackson.annotation.JsonIgnore;
@Entity
public class Vote extends Model {
......
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