Skip to content

Commit 3216b25

Browse files
committed
Added validations and preventing the same Idea from being added to a FP
1 parent aff1101 commit 3216b25

2 files changed

Lines changed: 12 additions & 3 deletions

File tree

src/main/java/edu/tamu/app/model/FeatureProposal.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import static org.hibernate.annotations.FetchMode.SELECT;
55

66
import java.util.ArrayList;
7+
import java.util.HashSet;
78
import java.util.List;
89

910
import javax.persistence.CascadeType;
@@ -82,15 +83,20 @@ public void setIdeas(List<Idea> ideas) {
8283
this.ideas.forEach(idea -> {
8384
removeVoter(idea.getAuthor());
8485
});
85-
this.ideas = ideas;
86+
HashSet<Idea> ideaSet = new HashSet<Idea>();
87+
ideaSet.addAll(ideas);
88+
this.ideas.clear();
89+
this.ideas.addAll(ideaSet);
8690
this.ideas.forEach(idea -> {
8791
addVoter(idea.getAuthor());
8892
});
8993
}
9094

9195
public void addIdea(Idea idea) {
92-
this.ideas.add(idea);
93-
addVoter(idea.getAuthor());
96+
if (!this.ideas.contains(idea)) {
97+
this.ideas.add(idea);
98+
addVoter(idea.getAuthor());
99+
}
94100
}
95101

96102
public void removeIdea(Idea idea) {

src/main/java/edu/tamu/app/model/validation/FeatureProposalValidator.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,8 @@ public class FeatureProposalValidator extends BaseModelValidator {
99
public FeatureProposalValidator() {
1010
String titleProperty = "title";
1111
this.addInputValidator(new InputValidator(InputValidationType.required, "Feature Proposals require a title", titleProperty, true));
12+
13+
String serviceProperty = "service";
14+
this.addInputValidator(new InputValidator(InputValidationType.required, "Feature Proposals require a Service", serviceProperty, true));
1215
}
1316
}

0 commit comments

Comments
 (0)