-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes #200
- Loading branch information
Showing
18 changed files
with
553 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package com.faforever.api.data.domain; | ||
|
||
import com.yahoo.elide.annotation.Include; | ||
import com.yahoo.elide.annotation.ReadPermission; | ||
import lombok.Setter; | ||
|
||
import javax.persistence.CascadeType; | ||
import javax.persistence.Entity; | ||
import javax.persistence.FetchType; | ||
import javax.persistence.JoinColumn; | ||
import javax.persistence.ManyToOne; | ||
import javax.persistence.OneToMany; | ||
import javax.persistence.Table; | ||
import java.util.List; | ||
|
||
@Entity | ||
@Table(name = "vote") | ||
@Include(type = Vote.TYPE_NAME) | ||
@ReadPermission(expression = "Prefab.Role.None") | ||
@Setter | ||
public class Vote extends AbstractEntity { | ||
public static final String TYPE_NAME = "vote"; | ||
|
||
private Player player; | ||
private VotingSubject votingSubject; | ||
private List<VotingAnswer> votingAnswers; | ||
|
||
@ManyToOne(fetch = FetchType.LAZY) | ||
@JoinColumn(name = "player_id") | ||
public Player getPlayer() { | ||
return player; | ||
} | ||
|
||
@ManyToOne(fetch = FetchType.LAZY) | ||
@JoinColumn(name = "voting_subject_id") | ||
public VotingSubject getVotingSubject() { | ||
return votingSubject; | ||
} | ||
|
||
@OneToMany(mappedBy = "vote", cascade = CascadeType.ALL, orphanRemoval = true) | ||
public List<VotingAnswer> getVotingAnswers() { | ||
return votingAnswers; | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
src/main/java/com/faforever/api/data/domain/VotingAnswer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package com.faforever.api.data.domain; | ||
|
||
import com.yahoo.elide.annotation.Include; | ||
import com.yahoo.elide.annotation.ReadPermission; | ||
import lombok.Setter; | ||
|
||
import javax.persistence.Entity; | ||
import javax.persistence.FetchType; | ||
import javax.persistence.JoinColumn; | ||
import javax.persistence.ManyToOne; | ||
import javax.persistence.Table; | ||
|
||
@Entity | ||
@Table(name = "voting_answer") | ||
@Include(type = VotingAnswer.TYPE_NAME) | ||
@ReadPermission(expression = "Prefab.Role.None") | ||
@Setter | ||
public class VotingAnswer extends AbstractEntity { | ||
public static final String TYPE_NAME = "votingAnswer"; | ||
|
||
private VotingQuestion votingQuestion; | ||
private Vote vote; | ||
private VotingChoice votingChoice; | ||
|
||
@ManyToOne(fetch = FetchType.LAZY) | ||
@JoinColumn(name = "voting_question_id") | ||
public VotingQuestion getVotingQuestion() { | ||
return votingQuestion; | ||
} | ||
|
||
@ManyToOne(fetch = FetchType.LAZY) | ||
@JoinColumn(name = "vote_id") | ||
public Vote getVote() { | ||
return vote; | ||
} | ||
|
||
@ManyToOne(fetch = FetchType.LAZY) | ||
@JoinColumn(name = "voting_choice_id") | ||
public VotingChoice getVotingChoice() { | ||
return votingChoice; | ||
} | ||
} |
75 changes: 75 additions & 0 deletions
75
src/main/java/com/faforever/api/data/domain/VotingChoice.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
package com.faforever.api.data.domain; | ||
|
||
import com.faforever.api.data.checks.permission.IsModerator; | ||
import com.faforever.api.data.listeners.VotingChoiceEnricher; | ||
import com.yahoo.elide.annotation.ComputedAttribute; | ||
import com.yahoo.elide.annotation.CreatePermission; | ||
import com.yahoo.elide.annotation.DeletePermission; | ||
import com.yahoo.elide.annotation.Exclude; | ||
import com.yahoo.elide.annotation.Include; | ||
import com.yahoo.elide.annotation.ReadPermission; | ||
import com.yahoo.elide.annotation.SharePermission; | ||
import com.yahoo.elide.annotation.UpdatePermission; | ||
import lombok.Setter; | ||
|
||
import javax.persistence.CascadeType; | ||
import javax.persistence.Column; | ||
import javax.persistence.Entity; | ||
import javax.persistence.EntityListeners; | ||
import javax.persistence.FetchType; | ||
import javax.persistence.JoinColumn; | ||
import javax.persistence.ManyToOne; | ||
import javax.persistence.OneToMany; | ||
import javax.persistence.Table; | ||
import javax.persistence.Transient; | ||
import javax.validation.constraints.NotNull; | ||
import java.util.List; | ||
|
||
@Entity | ||
@Table(name = "voting_choice") | ||
@ReadPermission(expression = "Prefab.Role.All") | ||
@SharePermission(expression = IsModerator.EXPRESSION) | ||
@DeletePermission(expression = IsModerator.EXPRESSION) | ||
@UpdatePermission(expression = IsModerator.EXPRESSION) | ||
@CreatePermission(expression = IsModerator.EXPRESSION) | ||
@Include(rootLevel = true, type = VotingChoice.TYPE_NAME) | ||
@Setter | ||
@EntityListeners(VotingChoiceEnricher.class) | ||
public class VotingChoice extends AbstractEntity { | ||
public static final String TYPE_NAME = "votingChoice"; | ||
|
||
private String name; | ||
private int numberOfAnswers; | ||
private String description; | ||
private VotingQuestion votingQuestion; | ||
private List<VotingAnswer> votingAnswers; | ||
|
||
@NotNull | ||
@Column(name = "name", nullable = false) | ||
public String getName() { | ||
return name; | ||
} | ||
|
||
@Transient | ||
@ComputedAttribute | ||
public int getNumberOfAnswers() { | ||
return numberOfAnswers; | ||
} | ||
|
||
@Column(name = "description") | ||
public String getDescription() { | ||
return description; | ||
} | ||
|
||
@JoinColumn(name = "voting_question_id") | ||
@ManyToOne(fetch = FetchType.LAZY) | ||
public VotingQuestion getVotingQuestion() { | ||
return votingQuestion; | ||
} | ||
|
||
@Exclude | ||
@OneToMany(mappedBy = "votingChoice", cascade = CascadeType.ALL, orphanRemoval = true) | ||
public List<VotingAnswer> getVotingAnswers() { | ||
return votingAnswers; | ||
} | ||
} |
79 changes: 79 additions & 0 deletions
79
src/main/java/com/faforever/api/data/domain/VotingQuestion.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
package com.faforever.api.data.domain; | ||
|
||
import com.faforever.api.data.checks.permission.IsModerator; | ||
import com.faforever.api.data.listeners.VotingQuestionEnricher; | ||
import com.yahoo.elide.annotation.ComputedAttribute; | ||
import com.yahoo.elide.annotation.CreatePermission; | ||
import com.yahoo.elide.annotation.DeletePermission; | ||
import com.yahoo.elide.annotation.Include; | ||
import com.yahoo.elide.annotation.ReadPermission; | ||
import com.yahoo.elide.annotation.SharePermission; | ||
import com.yahoo.elide.annotation.UpdatePermission; | ||
import lombok.Setter; | ||
|
||
import javax.persistence.CascadeType; | ||
import javax.persistence.Column; | ||
import javax.persistence.Entity; | ||
import javax.persistence.EntityListeners; | ||
import javax.persistence.FetchType; | ||
import javax.persistence.JoinColumn; | ||
import javax.persistence.ManyToOne; | ||
import javax.persistence.OneToMany; | ||
import javax.persistence.Table; | ||
import javax.persistence.Transient; | ||
import javax.validation.constraints.NotNull; | ||
import java.util.List; | ||
|
||
@Entity | ||
@Table(name = "voting_question") | ||
@ReadPermission(expression = "Prefab.Role.All") | ||
@SharePermission(expression = IsModerator.EXPRESSION) | ||
@DeletePermission(expression = IsModerator.EXPRESSION) | ||
@UpdatePermission(expression = IsModerator.EXPRESSION) | ||
@CreatePermission(expression = IsModerator.EXPRESSION) | ||
@Include(rootLevel = true, type = VotingQuestion.TYPE_NAME) | ||
@Setter | ||
@EntityListeners(VotingQuestionEnricher.class) | ||
public class VotingQuestion extends AbstractEntity { | ||
public static final String TYPE_NAME = "votingQuestion"; | ||
|
||
private int numberOfAnswers; | ||
private String question; | ||
private String description; | ||
private int maxAnswers; | ||
private VotingSubject votingSubject; | ||
private List<VotingChoice> votingChoices; | ||
|
||
@ManyToOne(fetch = FetchType.LAZY) | ||
@JoinColumn(name = "voting_subject_id") | ||
public VotingSubject getVotingSubject() { | ||
return votingSubject; | ||
} | ||
|
||
@NotNull | ||
@Column(name = "question", nullable = false) | ||
public String getQuestion() { | ||
return question; | ||
} | ||
|
||
@Column(name = "description") | ||
public String getDescription() { | ||
return description; | ||
} | ||
|
||
@Column(name = "max_answers") | ||
public int getMaxAnswers() { | ||
return maxAnswers; | ||
} | ||
|
||
@Transient | ||
@ComputedAttribute | ||
public int getNumberOfAnswers() { | ||
return numberOfAnswers; | ||
} | ||
|
||
@OneToMany(mappedBy = "votingQuestion", cascade = CascadeType.ALL, orphanRemoval = true) | ||
public List<VotingChoice> getVotingChoices() { | ||
return votingChoices; | ||
} | ||
} |
103 changes: 103 additions & 0 deletions
103
src/main/java/com/faforever/api/data/domain/VotingSubject.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
package com.faforever.api.data.domain; | ||
|
||
import com.faforever.api.data.checks.permission.IsModerator; | ||
import com.faforever.api.data.listeners.VotingSubjectEnricher; | ||
import com.yahoo.elide.annotation.ComputedAttribute; | ||
import com.yahoo.elide.annotation.CreatePermission; | ||
import com.yahoo.elide.annotation.DeletePermission; | ||
import com.yahoo.elide.annotation.Exclude; | ||
import com.yahoo.elide.annotation.Include; | ||
import com.yahoo.elide.annotation.ReadPermission; | ||
import com.yahoo.elide.annotation.SharePermission; | ||
import com.yahoo.elide.annotation.UpdatePermission; | ||
import lombok.Setter; | ||
import org.hibernate.validator.constraints.NotEmpty; | ||
|
||
import javax.persistence.CascadeType; | ||
import javax.persistence.Column; | ||
import javax.persistence.Entity; | ||
import javax.persistence.EntityListeners; | ||
import javax.persistence.OneToMany; | ||
import javax.persistence.Table; | ||
import javax.persistence.Transient; | ||
import javax.validation.constraints.DecimalMin; | ||
import javax.validation.constraints.NotNull; | ||
import java.time.OffsetDateTime; | ||
import java.util.List; | ||
|
||
@Entity | ||
@Table(name = "voting_subject") | ||
@Include(rootLevel = true, type = VotingSubject.TYPE_NAME) | ||
@ReadPermission(expression = "Prefab.Role.All") | ||
@SharePermission(expression = IsModerator.EXPRESSION) | ||
@DeletePermission(expression = IsModerator.EXPRESSION) | ||
@UpdatePermission(expression = IsModerator.EXPRESSION) | ||
@CreatePermission(expression = IsModerator.EXPRESSION) | ||
@Setter | ||
@EntityListeners(VotingSubjectEnricher.class) | ||
public class VotingSubject extends AbstractEntity { | ||
public static final String TYPE_NAME = "votingSubject"; | ||
|
||
private String name; | ||
private int numberOfVotes; | ||
private String topicUrl; | ||
private OffsetDateTime beginOfVoteTime; | ||
private OffsetDateTime endOfVoteTime; | ||
private int minGamesToVote; | ||
private String description; | ||
private List<Vote> votes; | ||
private List<VotingQuestion> votingQuestions; | ||
|
||
@Column(name = "name") | ||
@NotNull | ||
public String getName() { | ||
return name; | ||
} | ||
|
||
@Transient | ||
@ComputedAttribute | ||
public int getNumberOfVotes() { | ||
return numberOfVotes; | ||
} | ||
|
||
|
||
@NotNull | ||
@Column(name = "begin_of_vote_time") | ||
public OffsetDateTime getBeginOfVoteTime() { | ||
return beginOfVoteTime; | ||
} | ||
|
||
@NotNull | ||
@Column(name = "end_of_vote_time") | ||
public OffsetDateTime getEndOfVoteTime() { | ||
return endOfVoteTime; | ||
} | ||
|
||
@DecimalMin("0") | ||
@Column(name = "min_games_to_vote") | ||
public int getMinGamesToVote() { | ||
return minGamesToVote; | ||
} | ||
|
||
@Column(name = "description") | ||
public String getDescription() { | ||
return description; | ||
} | ||
|
||
@Column(name = "topic_url") | ||
public String getTopicUrl() { | ||
return topicUrl; | ||
} | ||
|
||
@Exclude | ||
@OneToMany(mappedBy = "votingSubject", cascade = CascadeType.ALL, orphanRemoval = true) | ||
public List<Vote> getVotes() { | ||
return votes; | ||
} | ||
|
||
@NotEmpty(message = "A subject needs at least one Question") | ||
@OneToMany(mappedBy = "votingSubject", cascade = CascadeType.ALL, orphanRemoval = true) | ||
public List<VotingQuestion> getVotingQuestions() { | ||
return votingQuestions; | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
src/main/java/com/faforever/api/data/listeners/VotingChoiceEnricher.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package com.faforever.api.data.listeners; | ||
|
||
import com.faforever.api.data.domain.VotingChoice; | ||
import org.springframework.stereotype.Component; | ||
|
||
import javax.persistence.PostLoad; | ||
|
||
@Component | ||
public class VotingChoiceEnricher { | ||
|
||
@PostLoad | ||
public void enhance(VotingChoice votingChoice) { | ||
votingChoice.setNumberOfAnswers(votingChoice.getVotingAnswers().size()); | ||
} | ||
} |
Oops, something went wrong.