-
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
15 changed files
with
457 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,46 @@ | ||
package com.faforever.api.data.domain; | ||
|
||
import com.yahoo.elide.annotation.Include; | ||
import com.yahoo.elide.annotation.ReadPermission; | ||
import lombok.Setter; | ||
import org.hibernate.validator.constraints.NotEmpty; | ||
|
||
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; | ||
} | ||
|
||
@NotEmpty(message = "At least one answer must be given, other wise vote is senseless") | ||
@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; | ||
} | ||
} |
62 changes: 62 additions & 0 deletions
62
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,62 @@ | ||
package com.faforever.api.data.domain; | ||
|
||
import com.faforever.api.data.checks.permission.IsModerator; | ||
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.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 | ||
public class VotingChoice extends AbstractEntity { | ||
public static final String TYPE_NAME = "votingChoice"; | ||
private String name; | ||
private String description; | ||
private VotingQuestion votingQuestion; | ||
private List<VotingAnswer> votingAnswers; | ||
|
||
@NotNull | ||
@Column(name = "name", nullable = false) | ||
public String getName() { | ||
return name; | ||
} | ||
|
||
@Column(name = "description") | ||
public String getDescription() { | ||
return description; | ||
} | ||
|
||
@JoinColumn(name = "voting_question_id") | ||
@ManyToOne(fetch = FetchType.LAZY) | ||
public VotingQuestion getVotingQuestion() { | ||
return votingQuestion; | ||
} | ||
|
||
@Transient | ||
@OneToMany(mappedBy = "votingChoice", cascade = CascadeType.ALL, orphanRemoval = true) | ||
public List<VotingAnswer> getVotingAnswers() { | ||
return votingAnswers; | ||
} | ||
} |
66 changes: 66 additions & 0 deletions
66
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,66 @@ | ||
package com.faforever.api.data.domain; | ||
|
||
import com.faforever.api.data.checks.permission.IsModerator; | ||
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.FetchType; | ||
import javax.persistence.JoinColumn; | ||
import javax.persistence.ManyToOne; | ||
import javax.persistence.OneToMany; | ||
import javax.persistence.Table; | ||
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 | ||
public class VotingQuestion extends AbstractEntity { | ||
public static final String TYPE_NAME = "votingQuestion"; | ||
private VotingSubject votingSubject; | ||
private String question; | ||
private String description; | ||
private int maxAnswers; | ||
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; | ||
} | ||
|
||
@OneToMany(mappedBy = "votingQuestion", cascade = CascadeType.ALL, orphanRemoval = true) | ||
public List<VotingChoice> getVotingChoices() { | ||
return votingChoices; | ||
} | ||
} |
90 changes: 90 additions & 0 deletions
90
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,90 @@ | ||
package com.faforever.api.data.domain; | ||
|
||
import com.faforever.api.data.checks.permission.IsModerator; | ||
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 org.hibernate.validator.constraints.NotEmpty; | ||
|
||
import javax.persistence.CascadeType; | ||
import javax.persistence.Column; | ||
import javax.persistence.Entity; | ||
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 | ||
public class VotingSubject extends AbstractEntity { | ||
public static final String TYPE_NAME = "votingSubject"; | ||
|
||
private String name; | ||
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; | ||
} | ||
|
||
@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; | ||
} | ||
|
||
@Transient | ||
@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; | ||
} | ||
} |
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
9 changes: 9 additions & 0 deletions
9
src/main/java/com/faforever/api/game/GamePlayerStatsRepository.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,9 @@ | ||
package com.faforever.api.game; | ||
|
||
import com.faforever.api.data.domain.GamePlayerStats; | ||
import com.faforever.api.data.domain.Player; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
public interface GamePlayerStatsRepository extends JpaRepository<GamePlayerStats, Integer> { | ||
int countByPlayer(Player player); | ||
} |
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
12 changes: 12 additions & 0 deletions
12
src/main/java/com/faforever/api/voting/VoteRepository.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,12 @@ | ||
package com.faforever.api.voting; | ||
|
||
import com.faforever.api.data.domain.Player; | ||
import com.faforever.api.data.domain.Vote; | ||
import com.faforever.api.data.domain.VotingSubject; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
import java.util.Optional; | ||
|
||
public interface VoteRepository extends JpaRepository<Vote, Integer> { | ||
Optional<Vote> findByPlayerAndVotingSubject(Player player, VotingSubject votingSubject); | ||
} |
7 changes: 7 additions & 0 deletions
7
src/main/java/com/faforever/api/voting/VotingAnswerRepository.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,7 @@ | ||
package com.faforever.api.voting; | ||
|
||
import com.faforever.api.data.domain.VotingAnswer; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
public interface VotingAnswerRepository extends JpaRepository<VotingAnswer, Integer> { | ||
} |
Oops, something went wrong.