#10 WJB3003 Spring Quick Poll

otevřený
WJB3003 chce sloučit 8 revizí z větve WJB3003/SpringQuickPoll:master do větve master
17 změnil soubory, kde provedl 594 přidání a 0 odebrání
  1. 32
    0
      src/main/java/io/zipcoder/tc_spring_poll_application/controller/ComputeResultController.java
  2. 70
    0
      src/main/java/io/zipcoder/tc_spring_poll_application/controller/PollController.java
  3. 45
    0
      src/main/java/io/zipcoder/tc_spring_poll_application/controller/VoteController.java
  4. 34
    0
      src/main/java/io/zipcoder/tc_spring_poll_application/domain/Option.java
  5. 50
    0
      src/main/java/io/zipcoder/tc_spring_poll_application/domain/Poll.java
  6. 32
    0
      src/main/java/io/zipcoder/tc_spring_poll_application/domain/Vote.java
  7. 22
    0
      src/main/java/io/zipcoder/tc_spring_poll_application/dtos/OptionCount.java
  8. 24
    0
      src/main/java/io/zipcoder/tc_spring_poll_application/dtos/VoteResult.java
  9. 73
    0
      src/main/java/io/zipcoder/tc_spring_poll_application/error/ErrorDetail.java
  10. 58
    0
      src/main/java/io/zipcoder/tc_spring_poll_application/error/RestExceptionHandler.java
  11. 23
    0
      src/main/java/io/zipcoder/tc_spring_poll_application/error/ValidationError.java
  12. 19
    0
      src/main/java/io/zipcoder/tc_spring_poll_application/excepection/ResourceNotFoundException.java
  13. 10
    0
      src/main/java/io/zipcoder/tc_spring_poll_application/repository/OptionRepository.java
  14. 10
    0
      src/main/java/io/zipcoder/tc_spring_poll_application/repository/PollRepository.java
  15. 16
    0
      src/main/java/io/zipcoder/tc_spring_poll_application/repository/VoteRepository.java
  16. 74
    0
      src/main/resources/import.sql
  17. 2
    0
      src/main/resources/messages.properties

+ 32
- 0
src/main/java/io/zipcoder/tc_spring_poll_application/controller/ComputeResultController.java Zobrazit soubor

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

+ 70
- 0
src/main/java/io/zipcoder/tc_spring_poll_application/controller/PollController.java Zobrazit soubor

@@ -0,0 +1,70 @@
1
+package io.zipcoder.tc_spring_poll_application.controller;
2
+
3
+import io.zipcoder.tc_spring_poll_application.domain.Poll;
4
+import io.zipcoder.tc_spring_poll_application.excepection.ResourceNotFoundException;
5
+import io.zipcoder.tc_spring_poll_application.repository.PollRepository;
6
+import org.springframework.beans.factory.annotation.Autowired;
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
+import javax.validation.Valid;
13
+import java.net.URI;
14
+
15
+@RestController
16
+public class PollController {
17
+
18
+    private PollRepository pollRepository;
19
+
20
+    @Autowired
21
+    public PollController(PollRepository pollRepository) {
22
+        this.pollRepository = pollRepository;
23
+    }
24
+
25
+    @RequestMapping(value="/polls", method= RequestMethod.GET)
26
+    public ResponseEntity<Iterable<Poll>> getAllPolls() {
27
+        Iterable<Poll> allPolls = pollRepository.findAll();
28
+        return new ResponseEntity<>(allPolls, HttpStatus.OK);
29
+    }
30
+
31
+    @RequestMapping(value="/polls", method=RequestMethod.POST)
32
+    public ResponseEntity<?> createPoll(@Valid @RequestBody Poll poll) {
33
+        poll = pollRepository.save(poll);
34
+
35
+        URI newPollUri = ServletUriComponentsBuilder
36
+                .fromCurrentRequest()
37
+                .path("/{id}")
38
+                .buildAndExpand(poll.getId())
39
+                .toUri();
40
+
41
+        return new ResponseEntity<>(newPollUri, HttpStatus.CREATED);
42
+    }
43
+
44
+    @RequestMapping(value="/polls/{pollId}", method=RequestMethod.GET)
45
+    public ResponseEntity<?> getPoll(@PathVariable Long pollId) {
46
+        verifyPoll(pollId);
47
+        Poll p = pollRepository.findOne(pollId);
48
+        return new ResponseEntity<> (p, HttpStatus.OK);
49
+    }
50
+
51
+    @RequestMapping(value="/polls/{pollId}", method=RequestMethod.PUT)
52
+    public ResponseEntity<?> updatePoll(@Valid @RequestBody Poll poll, @PathVariable Long pollId) {
53
+        verifyPoll(pollId);
54
+        Poll p = pollRepository.save(poll);
55
+        return new ResponseEntity<>(HttpStatus.OK);
56
+    }
57
+
58
+    @RequestMapping(value="/polls/{pollId}", method=RequestMethod.DELETE)
59
+    public ResponseEntity<?> deletePoll(@PathVariable Long pollId) {
60
+        verifyPoll(pollId);
61
+        pollRepository.delete(pollId);
62
+        return new ResponseEntity<>(HttpStatus.OK);
63
+    }
64
+
65
+    private void verifyPoll(Long pollId) {
66
+        Poll poll = pollRepository.findOne(pollId);
67
+        if(poll == null) throw new ResourceNotFoundException();
68
+    }
69
+
70
+}

+ 45
- 0
src/main/java/io/zipcoder/tc_spring_poll_application/controller/VoteController.java Zobrazit soubor

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

+ 34
- 0
src/main/java/io/zipcoder/tc_spring_poll_application/domain/Option.java Zobrazit soubor

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

+ 50
- 0
src/main/java/io/zipcoder/tc_spring_poll_application/domain/Poll.java Zobrazit soubor

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

+ 32
- 0
src/main/java/io/zipcoder/tc_spring_poll_application/domain/Vote.java Zobrazit soubor

@@ -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
+}

+ 22
- 0
src/main/java/io/zipcoder/tc_spring_poll_application/dtos/OptionCount.java Zobrazit soubor

@@ -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 Zobrazit soubor

@@ -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
+}

+ 73
- 0
src/main/java/io/zipcoder/tc_spring_poll_application/error/ErrorDetail.java Zobrazit soubor

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

+ 58
- 0
src/main/java/io/zipcoder/tc_spring_poll_application/error/RestExceptionHandler.java Zobrazit soubor

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

+ 23
- 0
src/main/java/io/zipcoder/tc_spring_poll_application/error/ValidationError.java Zobrazit soubor

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

+ 19
- 0
src/main/java/io/zipcoder/tc_spring_poll_application/excepection/ResourceNotFoundException.java Zobrazit soubor

@@ -0,0 +1,19 @@
1
+package io.zipcoder.tc_spring_poll_application.excepection;
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 RuntimeException{
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
+}

+ 10
- 0
src/main/java/io/zipcoder/tc_spring_poll_application/repository/OptionRepository.java Zobrazit soubor

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

+ 10
- 0
src/main/java/io/zipcoder/tc_spring_poll_application/repository/PollRepository.java Zobrazit soubor

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

+ 16
- 0
src/main/java/io/zipcoder/tc_spring_poll_application/repository/VoteRepository.java Zobrazit soubor

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

+ 74
- 0
src/main/resources/import.sql Zobrazit soubor

@@ -0,0 +1,74 @@
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
+insert into option (option_id, option_value, poll_id) values (2, 'Blue', 1);
4
+insert into option (option_id, option_value, poll_id) values (3, 'Orange', 1);
5
+
6
+insert into poll (poll_id, question) values (2, 'What is your favorite car?');
7
+insert into option (option_id, option_value, poll_id) values (4, 'Buick', 2);
8
+insert into option (option_id, option_value, poll_id) values (5, 'Ford', 2);
9
+insert into option (option_id, option_value, poll_id) values (6, 'Lexus', 2);
10
+
11
+insert into poll (poll_id, question) values (3, 'What is your favorite food?');
12
+insert into option (option_id, option_value, poll_id) values (7, 'Pizza', 3);
13
+insert into option (option_id, option_value, poll_id) values (8, 'Salad', 3);
14
+insert into option (option_id, option_value, poll_id) values (9, 'Burgers', 3);
15
+
16
+insert into poll (poll_id, question) values (4, 'What is your favorite Movie?');
17
+insert into option (option_id, option_value, poll_id) values (10, 'Avengers', 4);
18
+insert into option (option_id, option_value, poll_id) values (11, 'Titanic', 4);
19
+insert into option (option_id, option_value, poll_id) values (12, 'Taken', 4);
20
+
21
+insert into poll (poll_id, question) values (5, 'What is your favorite Drink?');
22
+insert into option (option_id, option_value, poll_id) values (13, 'Soda', 5);
23
+insert into option (option_id, option_value, poll_id) values (14, 'Water', 5);
24
+insert into option (option_id, option_value, poll_id) values (15, 'Tea', 5);
25
+
26
+insert into poll (poll_id, question) values (6, 'What is your favorite game?');
27
+insert into option (option_id, option_value, poll_id) values (16, 'Sorry', 6);
28
+insert into option (option_id, option_value, poll_id) values (17, 'Yatzee', 6);
29
+insert into option (option_id, option_value, poll_id) values (18, 'Orange', 6);
30
+
31
+insert into poll (poll_id, question) values (7, 'What is your favorite subject?');
32
+insert into option (option_id, option_value, poll_id) values (19, 'Math', 7);
33
+insert into option (option_id, option_value, poll_id) values (20, 'Science', 7);
34
+insert into option (option_id, option_value, poll_id) values (21, 'Gym', 7);
35
+
36
+insert into poll (poll_id, question) values (8, 'What is your favorite operating system?');
37
+insert into option (option_id, option_value, poll_id) values (22, 'Mac', 8);
38
+insert into option (option_id, option_value, poll_id) values (23, 'Windows', 8);
39
+insert into option (option_id, option_value, poll_id) values (24, 'Linux', 8);
40
+
41
+insert into poll (poll_id, question) values (9, 'What is your favorite phone?');
42
+insert into option (option_id, option_value, poll_id) values (25, 'Iphone', 9);
43
+insert into option (option_id, option_value, poll_id) values (26, 'Android', 9);
44
+insert into option (option_id, option_value, poll_id) values (27, 'Windows', 9);
45
+
46
+insert into poll (poll_id, question) values (10, 'What is your favorite company?');
47
+insert into option (option_id, option_value, poll_id) values (28, 'JPMC', 10);
48
+insert into option (option_id, option_value, poll_id) values (29, 'SEI', 10);
49
+insert into option (option_id, option_value, poll_id) values (30, 'Chatham', 10);
50
+
51
+insert into poll (poll_id, question) values (11, 'What is your favorite fruit?');
52
+insert into option (option_id, option_value, poll_id) values (31, 'Apple', 11);
53
+insert into option (option_id, option_value, poll_id) values (32, 'Orange', 11);
54
+insert into option (option_id, option_value, poll_id) values (33, 'Banana', 11);
55
+
56
+insert into poll (poll_id, question) values (12, 'What is your favorite vegetable?');
57
+insert into option (option_id, option_value, poll_id) values (34, 'String Beans', 12);
58
+insert into option (option_id, option_value, poll_id) values (35, 'Carrots', 12);
59
+insert into option (option_id, option_value, poll_id) values (35, 'Peas', 12);
60
+
61
+insert into poll (poll_id, question) values (13, 'What is your favorite state?');
62
+insert into option (option_id, option_value, poll_id) values (36, 'Delaware', 13);
63
+insert into option (option_id, option_value, poll_id) values (37, 'Florida', 13);
64
+insert into option (option_id, option_value, poll_id) values (38, 'California', 13);
65
+
66
+insert into poll (poll_id, question) values (14, 'What is your favorite country?');
67
+insert into option (option_id, option_value, poll_id) values (39, 'USA', 14);
68
+insert into option (option_id, option_value, poll_id) values (40, 'Europe', 14);
69
+insert into option (option_id, option_value, poll_id) values (41, 'Africa', 14);
70
+
71
+insert into poll (poll_id, question) values (15, 'What is your favorite search engine?');
72
+insert into option (option_id, option_value, poll_id) values (42, 'Google', 15);
73
+insert into option (option_id, option_value, poll_id) values (43, 'Bing', 15);
74
+insert into option (option_id, option_value, poll_id) values (44, 'Yahoo', 15);

+ 2
- 0
src/main/resources/messages.properties Zobrazit soubor

@@ -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}