Browse Source

all done except pagination?

thulasi 5 years ago
parent
commit
9978fb347a
19 changed files with 581 additions and 5 deletions
  1. 1
    1
      README.md
  2. 4
    4
      pom.xml
  3. 61
    0
      src/main/java/io/zipcoder/tc_spring_poll_application/RestExceptionHandler.java
  4. 84
    0
      src/main/java/io/zipcoder/tc_spring_poll_application/controllers/PollController.java
  5. 42
    0
      src/main/java/io/zipcoder/tc_spring_poll_application/controllers/VoteController.java
  6. 38
    0
      src/main/java/io/zipcoder/tc_spring_poll_application/domain/Option.java
  7. 62
    0
      src/main/java/io/zipcoder/tc_spring_poll_application/domain/Poll.java
  8. 32
    0
      src/main/java/io/zipcoder/tc_spring_poll_application/domain/Vote.java
  9. 61
    0
      src/main/java/io/zipcoder/tc_spring_poll_application/dto/error/ErrorDetail.java
  10. 22
    0
      src/main/java/io/zipcoder/tc_spring_poll_application/dto/error/ValidationError.java
  11. 31
    0
      src/main/java/io/zipcoder/tc_spring_poll_application/dtos/ComputeResultController.java
  12. 22
    0
      src/main/java/io/zipcoder/tc_spring_poll_application/dtos/OptionCount.java
  13. 24
    0
      src/main/java/io/zipcoder/tc_spring_poll_application/dtos/VoteResult.java
  14. 19
    0
      src/main/java/io/zipcoder/tc_spring_poll_application/exception/ResourceNotFoundException.java
  15. 8
    0
      src/main/java/io/zipcoder/tc_spring_poll_application/repositories/OptionRepository.java
  16. 8
    0
      src/main/java/io/zipcoder/tc_spring_poll_application/repositories/PollRepository.java
  17. 16
    0
      src/main/java/io/zipcoder/tc_spring_poll_application/repositories/VoteRepository.java
  18. 44
    0
      src/main/resources/import.sql
  19. 2
    0
      src/main/resources/messages.properties

+ 1
- 1
README.md View File

@@ -358,7 +358,7 @@ public Iterable<Vote> getVote(@PathVariable Long pollId) {
358 358
 
359 359
 * The final piece remaining for us is the implementation of the ComputeResult resource.
360 360
 * Because we don’t have any domain objects that can directly help generate this resource representation, we implement two Data Transfer Objects or DTOs—OptionCount and VoteResult
361
-* Create a sub package of `java` named `dtos`
361
+* Create a sub package of `java` named `io.zipcoder.tc_spring_poll_application.dtos`
362 362
 
363 363
 
364 364
 ## Part 4.1 - Create class `OptionCount`

+ 4
- 4
pom.xml View File

@@ -15,8 +15,8 @@
15 15
     </parent>
16 16
     <properties>
17 17
         <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
18
-        <start-class>io.zipcoder.tc_spring_poll_application.QuickPollApplication</start-class>
19
-        <java.version>1.7</java.version>
18
+        <start-class>io.zipcoder.springdemo.QuickPollApplication</start-class>
19
+        <java.version>1.8</java.version>
20 20
     </properties>
21 21
     <dependencies>
22 22
         <dependency>
@@ -33,8 +33,8 @@
33 33
             <scope>test</scope>
34 34
         </dependency>
35 35
         <dependency>
36
-            <groupId>org.hsqldb</groupId>
37
-            <artifactId>hsqldb</artifactId>
36
+            <groupId>com.h2database</groupId>
37
+            <artifactId>h2</artifactId>
38 38
             <scope>runtime</scope>
39 39
         </dependency>
40 40
 

+ 61
- 0
src/main/java/io/zipcoder/tc_spring_poll_application/RestExceptionHandler.java View File

@@ -0,0 +1,61 @@
1
+package io.zipcoder.tc_spring_poll_application;
2
+
3
+
4
+import io.zipcoder.tc_spring_poll_application.dto.error.ErrorDetail;
5
+import io.zipcoder.tc_spring_poll_application.dto.error.ValidationError;
6
+import io.zipcoder.tc_spring_poll_application.exception.ResourceNotFoundException;
7
+import org.springframework.beans.factory.annotation.Autowired;
8
+import org.springframework.context.MessageSource;
9
+import org.springframework.http.HttpStatus;
10
+import org.springframework.http.ResponseEntity;
11
+import org.springframework.validation.FieldError;
12
+import org.springframework.web.bind.MethodArgumentNotValidException;
13
+import org.springframework.web.bind.annotation.ControllerAdvice;
14
+import org.springframework.web.bind.annotation.ExceptionHandler;
15
+
16
+import javax.servlet.http.HttpServletRequest;
17
+import java.util.ArrayList;
18
+import java.util.Date;
19
+import java.util.List;
20
+
21
+@ControllerAdvice
22
+public class RestExceptionHandler {
23
+
24
+    @Autowired
25
+    MessageSource messageSource;
26
+
27
+    @ExceptionHandler(ResourceNotFoundException.class)
28
+    public ResponseEntity<?> handleResourceNotFoundException(ResourceNotFoundException rnfe, HttpServletRequest request) {
29
+        ErrorDetail errorDetail = new ErrorDetail();
30
+
31
+        //errorDetail.setTitle();
32
+        errorDetail.setTimeStamp(new Date().getTime());
33
+        errorDetail.setDetail(rnfe.getMessage());
34
+        errorDetail.setDeveloperMessage(rnfe.getLocalizedMessage());
35
+        return new ResponseEntity<>(errorDetail, HttpStatus.NOT_FOUND);
36
+    }
37
+
38
+    @ExceptionHandler(MethodArgumentNotValidException.class)
39
+    public ResponseEntity<?> handleValidationError(MethodArgumentNotValidException manve, HttpServletRequest request){
40
+        ErrorDetail errorDetail = new ErrorDetail();
41
+
42
+        errorDetail.setTimeStamp(new Date().getTime());
43
+
44
+        List<FieldError> fieldErrors =  manve.getBindingResult().getFieldErrors();
45
+        for(FieldError fe : fieldErrors) {
46
+
47
+            List<ValidationError> validationErrorList = errorDetail.getErrors().get(fe.getField());
48
+            if(validationErrorList == null) {
49
+                validationErrorList = new ArrayList<>();
50
+                errorDetail.getErrors().put(fe.getField(), validationErrorList);
51
+            }
52
+            ValidationError validationError = new ValidationError();
53
+            validationError.setCode(fe.getCode());
54
+            validationError.setMessage(messageSource.getMessage(fe, null));
55
+            validationErrorList.add(validationError);
56
+        }
57
+
58
+        return new ResponseEntity<>(errorDetail, HttpStatus.NOT_FOUND);
59
+    }
60
+
61
+}

+ 84
- 0
src/main/java/io/zipcoder/tc_spring_poll_application/controllers/PollController.java View File

@@ -0,0 +1,84 @@
1
+package io.zipcoder.tc_spring_poll_application.controllers;
2
+
3
+import io.zipcoder.tc_spring_poll_application.domain.Poll;
4
+import io.zipcoder.tc_spring_poll_application.exception.ResourceNotFoundException;
5
+import io.zipcoder.tc_spring_poll_application.repositories.PollRepository;
6
+import org.springframework.beans.factory.annotation.Autowired;
7
+import org.springframework.http.HttpHeaders;
8
+import org.springframework.http.HttpStatus;
9
+import org.springframework.http.ResponseEntity;
10
+import org.springframework.web.bind.annotation.*;
11
+import org.springframework.web.servlet.support.ServletUriComponentsBuilder;
12
+
13
+import javax.validation.Valid;
14
+import java.net.URI;
15
+
16
+@RestController
17
+public class PollController {
18
+
19
+
20
+    private PollRepository pollRepository;
21
+
22
+    @Autowired
23
+    public PollController(PollRepository pollRepository) {
24
+        this.pollRepository = pollRepository;
25
+    }
26
+
27
+    @RequestMapping(value="/polls", method= RequestMethod.GET)
28
+    public ResponseEntity<Iterable<Poll>> getAllPolls() {
29
+        Iterable<Poll> allPolls = pollRepository.findAll();
30
+        return new ResponseEntity<>(allPolls, HttpStatus.OK);
31
+    }
32
+
33
+    @RequestMapping(value="/polls", method=RequestMethod.POST)
34
+    public ResponseEntity<?> createPoll(@RequestBody @Valid Poll poll) {
35
+
36
+        HttpHeaders httpHeaders = new HttpHeaders();
37
+        poll = pollRepository.save(poll);
38
+        URI newPollUri = ServletUriComponentsBuilder
39
+                .fromCurrentRequest()
40
+                .path("/{id}")
41
+                .buildAndExpand(poll.getId())
42
+                .toUri();
43
+
44
+        httpHeaders.setLocation(newPollUri);
45
+        return new ResponseEntity<>(null, httpHeaders, HttpStatus.CREATED);
46
+    }
47
+
48
+    @RequestMapping(value="/polls/{pollId}", method=RequestMethod.GET)
49
+    public ResponseEntity<?> getPoll(@PathVariable Long pollId) throws ResourceNotFoundException {
50
+        if(verifyPoll(pollId)) {
51
+            Poll p = pollRepository.findOne(pollId);
52
+            return new ResponseEntity<> (p, HttpStatus.OK);
53
+        } else
54
+            throw new ResourceNotFoundException();
55
+    }
56
+
57
+    @RequestMapping(value="/polls/{pollId}", method=RequestMethod.PUT)
58
+    public ResponseEntity<?> updatePoll(@RequestBody @Valid Poll poll, @PathVariable Long pollId) throws ResourceNotFoundException {
59
+        // Save the entity
60
+        if(verifyPoll(pollId)) {
61
+            Poll p = pollRepository.save(poll);
62
+        } else
63
+            throw new ResourceNotFoundException();
64
+        return new ResponseEntity<>(HttpStatus.OK);
65
+    }
66
+
67
+    @RequestMapping(value="/polls/{pollId}", method=RequestMethod.DELETE)
68
+    public ResponseEntity<?> deletePoll(@PathVariable Long pollId) throws ResourceNotFoundException {
69
+
70
+            if(verifyPoll(pollId))
71
+                pollRepository.delete(pollId);
72
+            else
73
+                throw new ResourceNotFoundException();
74
+
75
+        return new ResponseEntity<>(HttpStatus.OK);
76
+    }
77
+
78
+    public boolean verifyPoll(Long pollId) throws ResourceNotFoundException{
79
+        if(pollRepository.findOne(pollId) != null)
80
+            return true;
81
+        else return false;
82
+    }
83
+
84
+}

+ 42
- 0
src/main/java/io/zipcoder/tc_spring_poll_application/controllers/VoteController.java View File

@@ -0,0 +1,42 @@
1
+package io.zipcoder.tc_spring_poll_application.controllers;
2
+
3
+import io.zipcoder.tc_spring_poll_application.domain.Vote;
4
+import io.zipcoder.tc_spring_poll_application.repositories.VoteRepository;
5
+import org.springframework.beans.factory.annotation.Autowired;
6
+import org.springframework.http.HttpHeaders;
7
+import org.springframework.http.HttpStatus;
8
+import org.springframework.http.ResponseEntity;
9
+import org.springframework.web.bind.annotation.*;
10
+import org.springframework.web.servlet.support.ServletUriComponentsBuilder;
11
+
12
+@RestController
13
+public class VoteController {
14
+
15
+    private VoteRepository voteRepository;
16
+
17
+    @Autowired
18
+    public VoteController(VoteRepository voteRepository) {
19
+        this.voteRepository = voteRepository;
20
+    }
21
+
22
+    @RequestMapping(value = "/polls/{pollId}/votes", method = RequestMethod.POST)
23
+    public ResponseEntity<?> createVote(@PathVariable Long pollId, @RequestBody Vote
24
+            vote) {
25
+        vote = voteRepository.save(vote);
26
+        // Set the headers for the newly created resource
27
+        HttpHeaders responseHeaders = new HttpHeaders();
28
+        responseHeaders.setLocation(ServletUriComponentsBuilder.
29
+                fromCurrentRequest().path("/{id}").buildAndExpand(vote.getId()).toUri());
30
+        return new ResponseEntity<>(null, responseHeaders, HttpStatus.CREATED);
31
+    }
32
+
33
+    @RequestMapping(value = "/polls/votes", method = RequestMethod.GET)
34
+    public Iterable<Vote> getAllVotes(){
35
+        return voteRepository.findAll();
36
+    }
37
+
38
+    @RequestMapping(value = "/polls/{pollId}/votes", method = RequestMethod.GET)
39
+    public Iterable<Vote> getVote(@PathVariable Long pollId){
40
+        return voteRepository.findVotesByPoll(pollId);
41
+    }
42
+}

+ 38
- 0
src/main/java/io/zipcoder/tc_spring_poll_application/domain/Option.java View File

@@ -0,0 +1,38 @@
1
+package io.zipcoder.tc_spring_poll_application.domain;
2
+
3
+import javax.persistence.*;
4
+
5
+@Entity
6
+public class Option {
7
+
8
+    @Id
9
+    @GeneratedValue(strategy = GenerationType.IDENTITY)
10
+    @Column(name = "OPTION_ID")
11
+    private Long id;
12
+
13
+    @Column(name = "OPTION_VALUE")
14
+    private String value;
15
+
16
+    public Option(String value) {
17
+        this.value = value;
18
+    }
19
+
20
+    public Option() {
21
+    }
22
+
23
+    public Long getId() {
24
+        return id;
25
+    }
26
+
27
+    public void setId(Long id) {
28
+        this.id = id;
29
+    }
30
+
31
+    public String getValue() {
32
+        return value;
33
+    }
34
+
35
+    public void setValue(String value) {
36
+        this.value = value;
37
+    }
38
+}

+ 62
- 0
src/main/java/io/zipcoder/tc_spring_poll_application/domain/Poll.java View File

@@ -0,0 +1,62 @@
1
+package io.zipcoder.tc_spring_poll_application.domain;
2
+
3
+import org.hibernate.annotations.Cascade;
4
+import org.hibernate.validator.constraints.NotEmpty;
5
+
6
+import javax.persistence.*;
7
+import javax.validation.constraints.Size;
8
+import java.util.List;
9
+import javax.validation.Valid;
10
+import java.util.Set;
11
+
12
+@Entity
13
+public class Poll {
14
+
15
+    @Id
16
+    @GeneratedValue(strategy = GenerationType.IDENTITY)
17
+    @Column(name = "POLL_ID")
18
+    private Long id;
19
+
20
+    @Column(name = "QUESTION")
21
+    @NotEmpty
22
+    private String question;
23
+
24
+    public Poll() {
25
+    }
26
+
27
+    public Poll(String question, List<Option> options) {
28
+        this.question = question;
29
+        this.options = options;
30
+    }
31
+
32
+    @OneToMany(cascade = CascadeType.ALL)
33
+    @JoinColumn(name = "POLL_ID")
34
+    @OrderBy
35
+    @Size(min = 2, max = 6)
36
+    private List<Option> options;
37
+
38
+    public Long getId() {
39
+        return id;
40
+    }
41
+
42
+    public void setId(Long id) {
43
+        this.id = id;
44
+    }
45
+
46
+    public String getQuestion() {
47
+        return question;
48
+    }
49
+
50
+    public void setQuestion(String question) {
51
+        this.question = question;
52
+    }
53
+
54
+    public List<Option> getOptions() {
55
+        return options;
56
+    }
57
+
58
+    public void setOptions(List<Option> options) {
59
+        this.options = options;
60
+    }
61
+
62
+}

+ 32
- 0
src/main/java/io/zipcoder/tc_spring_poll_application/domain/Vote.java View File

@@ -0,0 +1,32 @@
1
+package io.zipcoder.tc_spring_poll_application.domain;
2
+
3
+import javax.persistence.*;
4
+
5
+@Entity
6
+public class Vote {
7
+
8
+    @Id
9
+    @GeneratedValue
10
+    @Column(name = "VOTE_ID")
11
+    private Long id;
12
+
13
+    @ManyToOne
14
+    @JoinColumn(name = "OPTION_ID")
15
+    private Option option;
16
+
17
+    public Long getId() {
18
+        return id;
19
+    }
20
+
21
+    public void setId(Long id) {
22
+        this.id = id;
23
+    }
24
+
25
+    public Option getOption() {
26
+        return option;
27
+    }
28
+
29
+    public void setOption(Option option) {
30
+        this.option = option;
31
+    }
32
+}

+ 61
- 0
src/main/java/io/zipcoder/tc_spring_poll_application/dto/error/ErrorDetail.java View File

@@ -0,0 +1,61 @@
1
+package io.zipcoder.tc_spring_poll_application.dto.error;
2
+
3
+import java.util.List;
4
+import java.util.Map;
5
+
6
+public class ErrorDetail {
7
+    String title;
8
+    int status;
9
+    String detail;
10
+    long timeStamp;
11
+    String developerMessage;
12
+    Map<String, List<ValidationError>> errors;
13
+
14
+    public String getTitle() {
15
+        return title;
16
+    }
17
+
18
+    public void setTitle(String title) {
19
+        this.title = title;
20
+    }
21
+
22
+    public int getStatus() {
23
+        return status;
24
+    }
25
+
26
+    public void setStatus(int status) {
27
+        this.status = status;
28
+    }
29
+
30
+    public String getDetail() {
31
+        return detail;
32
+    }
33
+
34
+    public void setDetail(String detail) {
35
+        this.detail = detail;
36
+    }
37
+
38
+    public long getTimeStamp() {
39
+        return timeStamp;
40
+    }
41
+
42
+    public void setTimeStamp(long timeStamp) {
43
+        this.timeStamp = timeStamp;
44
+    }
45
+
46
+    public String getDeveloperMessage() {
47
+        return developerMessage;
48
+    }
49
+
50
+    public void setDeveloperMessage(String developerMessage) {
51
+        this.developerMessage = developerMessage;
52
+    }
53
+
54
+    public Map<String, List<ValidationError>> getErrors() {
55
+        return errors;
56
+    }
57
+
58
+    public void setErrors(Map<String, List<ValidationError>> errors) {
59
+        this.errors = errors;
60
+    }
61
+}

+ 22
- 0
src/main/java/io/zipcoder/tc_spring_poll_application/dto/error/ValidationError.java View File

@@ -0,0 +1,22 @@
1
+package io.zipcoder.tc_spring_poll_application.dto.error;
2
+
3
+public class ValidationError {
4
+    String code;
5
+    String message;
6
+
7
+    public String getCode() {
8
+        return code;
9
+    }
10
+
11
+    public void setCode(String code) {
12
+        this.code = code;
13
+    }
14
+
15
+    public String getMessage() {
16
+        return message;
17
+    }
18
+
19
+    public void setMessage(String message) {
20
+        this.message = message;
21
+    }
22
+}

+ 31
- 0
src/main/java/io/zipcoder/tc_spring_poll_application/dtos/ComputeResultController.java View File

@@ -0,0 +1,31 @@
1
+package io.zipcoder.tc_spring_poll_application.dtos;
2
+
3
+import io.zipcoder.tc_spring_poll_application.domain.Vote;
4
+import io.zipcoder.tc_spring_poll_application.repositories.VoteRepository;
5
+import org.springframework.beans.factory.annotation.Autowired;
6
+import org.springframework.http.HttpStatus;
7
+import org.springframework.http.ResponseEntity;
8
+import org.springframework.web.bind.annotation.RequestMapping;
9
+import org.springframework.web.bind.annotation.RequestMethod;
10
+import org.springframework.web.bind.annotation.RequestParam;
11
+import org.springframework.web.bind.annotation.RestController;
12
+
13
+@RestController
14
+public class ComputeResultController {
15
+
16
+    private VoteRepository voteRepository;
17
+
18
+    @Autowired
19
+    public ComputeResultController(VoteRepository voteRepository) {
20
+        this.voteRepository = voteRepository;
21
+    }
22
+
23
+    @RequestMapping(value = "/computeresult", method = RequestMethod.GET)
24
+    public ResponseEntity<?> computeResult(@RequestParam Long pollId) {
25
+        VoteResult voteResult = new VoteResult();
26
+        Iterable<Vote> allVotes = voteRepository.findVotesByPoll(pollId);
27
+
28
+        //TODO: Implement algorithm to count votes
29
+        return new ResponseEntity<VoteResult>(voteResult, HttpStatus.OK);
30
+    }
31
+}

+ 22
- 0
src/main/java/io/zipcoder/tc_spring_poll_application/dtos/OptionCount.java View File

@@ -0,0 +1,22 @@
1
+package io.zipcoder.tc_spring_poll_application.dtos;
2
+
3
+public class OptionCount {
4
+    private Long optionId;
5
+    private int count;
6
+
7
+    public Long getOptionId() {
8
+        return optionId;
9
+    }
10
+
11
+    public void setOptionId(Long optionId) {
12
+        this.optionId = optionId;
13
+    }
14
+
15
+    public int getCount() {
16
+        return count;
17
+    }
18
+
19
+    public void setCount(int count) {
20
+        this.count = count;
21
+    }
22
+}

+ 24
- 0
src/main/java/io/zipcoder/tc_spring_poll_application/dtos/VoteResult.java View File

@@ -0,0 +1,24 @@
1
+package io.zipcoder.tc_spring_poll_application.dtos;
2
+
3
+import java.util.Collection;
4
+
5
+public class VoteResult {
6
+    private int totalVotes;
7
+    private Collection<OptionCount> results;
8
+
9
+    public int getTotalVotes() {
10
+        return totalVotes;
11
+    }
12
+
13
+    public void setTotalVotes(int totalVotes) {
14
+        this.totalVotes = totalVotes;
15
+    }
16
+
17
+    public Collection<OptionCount> getResults() {
18
+        return results;
19
+    }
20
+
21
+    public void setResults(Collection<OptionCount> results) {
22
+        this.results = results;
23
+    }
24
+}

+ 19
- 0
src/main/java/io/zipcoder/tc_spring_poll_application/exception/ResourceNotFoundException.java View File

@@ -0,0 +1,19 @@
1
+package io.zipcoder.tc_spring_poll_application.exception;
2
+
3
+import org.springframework.http.HttpStatus;
4
+import org.springframework.web.bind.annotation.ResponseStatus;
5
+
6
+@ResponseStatus(HttpStatus.NOT_FOUND)
7
+public class ResourceNotFoundException extends Exception {
8
+
9
+    public ResourceNotFoundException() {
10
+    }
11
+
12
+    public ResourceNotFoundException(String message) {
13
+        super(message);
14
+    }
15
+
16
+    public ResourceNotFoundException(String message, Throwable cause) {
17
+        super(message, cause);
18
+    }
19
+}

+ 8
- 0
src/main/java/io/zipcoder/tc_spring_poll_application/repositories/OptionRepository.java View File

@@ -0,0 +1,8 @@
1
+package io.zipcoder.tc_spring_poll_application.repositories;
2
+
3
+import io.zipcoder.tc_spring_poll_application.domain.Option;
4
+import org.springframework.data.repository.CrudRepository;
5
+import org.springframework.data.repository.PagingAndSortingRepository;
6
+
7
+public interface OptionRepository extends PagingAndSortingRepository<Option, Long> {
8
+}

+ 8
- 0
src/main/java/io/zipcoder/tc_spring_poll_application/repositories/PollRepository.java View File

@@ -0,0 +1,8 @@
1
+package io.zipcoder.tc_spring_poll_application.repositories;
2
+
3
+import io.zipcoder.tc_spring_poll_application.domain.Poll;
4
+import org.springframework.data.repository.CrudRepository;
5
+import org.springframework.data.repository.PagingAndSortingRepository;
6
+
7
+public interface PollRepository extends PagingAndSortingRepository<Poll, Long> {
8
+}

+ 16
- 0
src/main/java/io/zipcoder/tc_spring_poll_application/repositories/VoteRepository.java View File

@@ -0,0 +1,16 @@
1
+package io.zipcoder.tc_spring_poll_application.repositories;
2
+
3
+import io.zipcoder.tc_spring_poll_application.domain.Option;
4
+import io.zipcoder.tc_spring_poll_application.domain.Vote;
5
+import org.springframework.data.jpa.repository.JpaRepository;
6
+import org.springframework.data.jpa.repository.Query;
7
+import org.springframework.data.repository.CrudRepository;
8
+import org.springframework.data.repository.PagingAndSortingRepository;
9
+
10
+public interface VoteRepository extends PagingAndSortingRepository<Vote, Long> {
11
+    @Query(value = "SELECT v.* " +
12
+    "FROM Option o, Vote v " +
13
+    "WHERE o.POLL_ID = ?1 " +
14
+    "AND v.OPTION_ID = o.OPTION_ID", nativeQuery = true)
15
+    public Iterable<Vote> findVotesByPoll(Long pollId);
16
+}

+ 44
- 0
src/main/resources/import.sql View File

@@ -0,0 +1,44 @@
1
+insert into poll (poll_id, question) values (1, 'What is your favorite color?');
2
+insert into option (option_id, option_value, poll_id) values (1, 'Red', 1);
3
+
4
+insert into poll (poll_id, question) values (2, 'What is your favorite color?');
5
+insert into option (option_id, option_value, poll_id) values (2, 'Red', 2);
6
+
7
+insert into poll (poll_id, question) values (3, 'What is your favorite color?');
8
+insert into option (option_id, option_value, poll_id) values (3, 'Red', 3);
9
+
10
+insert into poll (poll_id, question) values (4, 'What is your favorite color?');
11
+insert into option (option_id, option_value, poll_id) values (4, 'Red', 4);
12
+
13
+insert into poll (poll_id, question) values (5, 'What is your favorite color?');
14
+insert into option (option_id, option_value, poll_id) values (5, 'Red', 5);
15
+
16
+insert into poll (poll_id, question) values (6, 'What is your favorite color?');
17
+insert into option (option_id, option_value, poll_id) values (6, 'Red', 6);
18
+
19
+insert into poll (poll_id, question) values (7, 'What is your favorite color?');
20
+insert into option (option_id, option_value, poll_id) values (7, 'Red', 7);
21
+
22
+insert into poll (poll_id, question) values (8, 'What is your favorite color?');
23
+insert into option (option_id, option_value, poll_id) values (8, 'Red', 8);
24
+
25
+insert into poll (poll_id, question) values (9, 'What is your favorite color?');
26
+insert into option (option_id, option_value, poll_id) values (9, 'Red', 9);
27
+
28
+insert into poll (poll_id, question) values (10, 'What is your favorite color?');
29
+insert into option (option_id, option_value, poll_id) values (10, 'Red', 10);
30
+
31
+insert into poll (poll_id, question) values (11, 'What is your favorite color?');
32
+insert into option (option_id, option_value, poll_id) values (11, 'Red', 11);
33
+
34
+insert into poll (poll_id, question) values (12, 'What is your favorite color?');
35
+insert into option (option_id, option_value, poll_id) values (12, 'Red', 12);
36
+
37
+insert into poll (poll_id, question) values (13, 'What is your favorite color?');
38
+insert into option (option_id, option_value, poll_id) values (13, 'Red', 13);
39
+
40
+insert into poll (poll_id, question) values (14, 'What is your favorite color?');
41
+insert into option (option_id, option_value, poll_id) values (14, 'Red', 14);
42
+
43
+insert into poll (poll_id, question) values (15, 'What is your favorite color?');
44
+insert into option (option_id, option_value, poll_id) values (15, 'Red', 15);

+ 2
- 0
src/main/resources/messages.properties View File

@@ -0,0 +1,2 @@
1
+NotEmpty.poll.question=Question is a required field
2
+Size.poll.options=Options must be greater than {2} and less than {1}