Skip to content

Commit

Permalink
Updated survey so it will not add more responses after it has been cl…
Browse files Browse the repository at this point in the history
…osed.
  • Loading branch information
bardia-p committed Nov 3, 2023
1 parent 0f1786f commit d95b1d6
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/main/java/com/opinionowl/opinionowl/models/Survey.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,12 @@ public boolean removeQuestion(Long questionId){
* Adds a response to the survey.
* @param response the response to add to the survey.
*/
public void addResponse(Response response){
this.responses.add(response);
public boolean addResponse(Response response){
if (!closed){
this.responses.add(response);
return true;
}
return false;
}

/**
Expand Down
9 changes: 9 additions & 0 deletions src/test/java/com/opinionowl/opinionowl/SurveyTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,15 @@ public void testPersist() {

surveyRepository.save(survey);

survey.setClosed(true);

Response r2 = new Response(new HashMap<Long, String>(){{
put(Long.valueOf(1), "yo");
put(Long.valueOf(2), "b");
}});

survey.addResponse(r2);

List<Survey> results = surveyRepository.findAll();
for (Survey r : results){
System.out.println(r.toString());
Expand Down

0 comments on commit d95b1d6

Please sign in to comment.