Jennifer Chao 5 lat temu
rodzic
commit
952198da02
17 zmienionych plików z 635 dodań i 0 usunięć
  1. 63
    0
      src/main/java/io/zipcoder/tc_spring_poll_application/controller/ComputeResultController.java
  2. 75
    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. 31
    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. 23
    0
      src/main/java/io/zipcoder/tc_spring_poll_application/dtos/OptionCount.java
  8. 28
    0
      src/main/java/io/zipcoder/tc_spring_poll_application/dtos/VoteResult.java
  9. 62
    0
      src/main/java/io/zipcoder/tc_spring_poll_application/error/ErrorDetail.java
  10. 23
    0
      src/main/java/io/zipcoder/tc_spring_poll_application/error/ValidationError.java
  11. 19
    0
      src/main/java/io/zipcoder/tc_spring_poll_application/exception/ResourceNotFoundException.java
  12. 63
    0
      src/main/java/io/zipcoder/tc_spring_poll_application/exception/RestExceptionHandler.java
  13. 7
    0
      src/main/java/io/zipcoder/tc_spring_poll_application/repositories/OptionRepository.java
  14. 8
    0
      src/main/java/io/zipcoder/tc_spring_poll_application/repositories/PollRepository.java
  15. 15
    0
      src/main/java/io/zipcoder/tc_spring_poll_application/repositories/VoteRepository.java
  16. 89
    0
      src/main/resources/import.sql
  17. 2
    0
      src/main/resources/messages.properties

+ 63
- 0
src/main/java/io/zipcoder/tc_spring_poll_application/controller/ComputeResultController.java Wyświetl plik

1
+package io.zipcoder.tc_spring_poll_application.controller;
2
+
3
+import io.zipcoder.tc_spring_poll_application.domain.Option;
4
+import io.zipcoder.tc_spring_poll_application.domain.Vote;
5
+import io.zipcoder.tc_spring_poll_application.dtos.OptionCount;
6
+import io.zipcoder.tc_spring_poll_application.dtos.VoteResult;
7
+import io.zipcoder.tc_spring_poll_application.repositories.VoteRepository;
8
+import org.springframework.beans.factory.annotation.Autowired;
9
+import org.springframework.http.HttpStatus;
10
+import org.springframework.http.ResponseEntity;
11
+import org.springframework.web.bind.annotation.GetMapping;
12
+import org.springframework.web.bind.annotation.RequestParam;
13
+import org.springframework.web.bind.annotation.RestController;
14
+
15
+import java.util.Collection;
16
+import java.util.Map;
17
+import java.util.TreeMap;
18
+
19
+@RestController
20
+public class ComputeResultController {
21
+
22
+    private final VoteRepository voteRepository;
23
+
24
+    @Autowired
25
+    public ComputeResultController(VoteRepository voteRepository) {
26
+        this.voteRepository = voteRepository;
27
+    }
28
+
29
+    @GetMapping("/computeresult")
30
+    public ResponseEntity<?> computeResult(@RequestParam Long pollId) {
31
+        VoteResult voteResult = new VoteResult();
32
+        Iterable<Vote> allVotes = voteRepository.findVotesByPoll(pollId);
33
+
34
+        Map<Long, Integer> optionCounts = countOptions(allVotes);
35
+        addOptionCountsToVoteResult(optionCounts, voteResult);
36
+
37
+        return new ResponseEntity<>(voteResult, HttpStatus.OK);
38
+    }
39
+
40
+    private Map<Long, Integer> countOptions(Iterable<Vote> allVotes) {
41
+        Map<Long, Integer> optionCounts = new TreeMap<>();
42
+
43
+        for (Vote vote : allVotes) {
44
+            if (!optionCounts.containsKey(vote.getOption().getId())) {
45
+                optionCounts.put(vote.getOption().getId(), 1);
46
+            } else {
47
+                optionCounts.put(vote.getOption().getId(), optionCounts.get(vote.getOption().getId()) + 1);
48
+            }
49
+        }
50
+
51
+        return optionCounts;
52
+    }
53
+
54
+    private void addOptionCountsToVoteResult(Map<Long, Integer> optionCounts, VoteResult voteResult) {
55
+        for (Long id : optionCounts.keySet()) {
56
+            OptionCount optionCount = new OptionCount();
57
+            optionCount.setOptionId(id);
58
+            optionCount.setCount(optionCounts.get(id));
59
+            voteResult.getResults().add(optionCount);
60
+        }
61
+    }
62
+
63
+}

+ 75
- 0
src/main/java/io/zipcoder/tc_spring_poll_application/controller/PollController.java Wyświetl plik

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

+ 45
- 0
src/main/java/io/zipcoder/tc_spring_poll_application/controller/VoteController.java Wyświetl plik

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.repositories.VoteRepository;
5
+import org.springframework.beans.factory.annotation.Autowired;
6
+import org.springframework.http.HttpHeaders;
7
+import org.springframework.http.HttpRequest;
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 java.net.URI;
14
+
15
+@RestController
16
+public class VoteController {
17
+
18
+    private VoteRepository voteRepository;
19
+
20
+    @Autowired
21
+    public VoteController(VoteRepository voteRepository) {
22
+        this.voteRepository = voteRepository;
23
+    }
24
+
25
+    @RequestMapping(value = "/polls/{pollId}/votes", method = RequestMethod.POST)
26
+    public ResponseEntity<?> createVote(@PathVariable Long pollId, @RequestBody Vote
27
+            vote) {
28
+        vote = voteRepository.save(vote);
29
+        // Set the headers for the newly created resource
30
+        HttpHeaders responseHeaders = new HttpHeaders();
31
+        responseHeaders.setLocation(ServletUriComponentsBuilder.
32
+                fromCurrentRequest().path("/{id}").buildAndExpand(vote.getId()).toUri());
33
+        return new ResponseEntity<>(vote, 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.findVotesByPoll(pollId);
44
+    }
45
+}

+ 31
- 0
src/main/java/io/zipcoder/tc_spring_poll_application/domain/Option.java Wyświetl plik

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.AUTO)
10
+    @Column(name = "OPTION_ID")
11
+    private Long id;
12
+
13
+    @Column(name = "OPTION_VALUE")
14
+    private String value;
15
+
16
+    public Long getId() {
17
+        return id;
18
+    }
19
+
20
+    public void setId(Long id) {
21
+        this.id = id;
22
+    }
23
+
24
+    public String getValue() {
25
+        return value;
26
+    }
27
+
28
+    public void setValue(String value) {
29
+        this.value = value;
30
+    }
31
+}

+ 50
- 0
src/main/java/io/zipcoder/tc_spring_poll_application/domain/Poll.java Wyświetl plik

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(strategy = GenerationType.AUTO)
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 Wyświetl plik

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(strategy = GenerationType.AUTO)
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
+}

+ 23
- 0
src/main/java/io/zipcoder/tc_spring_poll_application/dtos/OptionCount.java Wyświetl plik

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

+ 28
- 0
src/main/java/io/zipcoder/tc_spring_poll_application/dtos/VoteResult.java Wyświetl plik

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

+ 62
- 0
src/main/java/io/zipcoder/tc_spring_poll_application/error/ErrorDetail.java Wyświetl plik

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 String getTitle() {
16
+        return title;
17
+    }
18
+
19
+    public void setTitle(String title) {
20
+        this.title = title;
21
+    }
22
+
23
+    public int getStatus() {
24
+        return status;
25
+    }
26
+
27
+    public void setStatus(int status) {
28
+        this.status = status;
29
+    }
30
+
31
+    public String getDetail() {
32
+        return detail;
33
+    }
34
+
35
+    public void setDetail(String detail) {
36
+        this.detail = detail;
37
+    }
38
+
39
+    public long getTimeStamp() {
40
+        return timeStamp;
41
+    }
42
+
43
+    public void setTimeStamp(long timeStamp) {
44
+        this.timeStamp = timeStamp;
45
+    }
46
+
47
+    public String getDeveloperMessage() {
48
+        return developerMessage;
49
+    }
50
+
51
+    public void setDeveloperMessage(String developerMessage) {
52
+        this.developerMessage = developerMessage;
53
+    }
54
+
55
+    public Map<String, List<ValidationError>> getErrors() {
56
+        return errors;
57
+    }
58
+
59
+    public void setErrors(Map<String, List<ValidationError>> errors) {
60
+        this.errors = errors;
61
+    }
62
+}

+ 23
- 0
src/main/java/io/zipcoder/tc_spring_poll_application/error/ValidationError.java Wyświetl plik

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/exception/ResourceNotFoundException.java Wyświetl plik

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 RuntimeException {
8
+
9
+    public ResourceNotFoundException(){}
10
+
11
+    public ResourceNotFoundException(String message) {
12
+        super(message);
13
+    }
14
+
15
+    public ResourceNotFoundException(String message, Throwable cause) {
16
+        super(message, cause);
17
+    }
18
+
19
+}

+ 63
- 0
src/main/java/io/zipcoder/tc_spring_poll_application/exception/RestExceptionHandler.java Wyświetl plik

1
+package io.zipcoder.tc_spring_poll_application.exception;
2
+
3
+import io.zipcoder.tc_spring_poll_application.error.ErrorDetail;
4
+import io.zipcoder.tc_spring_poll_application.error.ValidationError;
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
+import java.util.Map;
19
+
20
+@ControllerAdvice
21
+public class RestExceptionHandler {
22
+
23
+    private final MessageSource messageSource;
24
+
25
+    @Autowired
26
+    public RestExceptionHandler(MessageSource messageSource) {
27
+        this.messageSource = messageSource;
28
+    }
29
+
30
+    @ExceptionHandler(ResourceNotFoundException.class)
31
+    public ResponseEntity<?> handleResourceNotFoundException(ResourceNotFoundException rnfe, HttpServletRequest request) {
32
+        ErrorDetail errorDetail = new ErrorDetail();
33
+        errorDetail.setTitle(request.getMethod());
34
+        errorDetail.setStatus(404);
35
+        errorDetail.setDetail(rnfe.getCause().toString());
36
+        errorDetail.setTimeStamp(new Date().getTime());
37
+        errorDetail.setDeveloperMessage(rnfe.getMessage());
38
+        return new ResponseEntity<>(errorDetail, HttpStatus.NOT_FOUND);
39
+    }
40
+
41
+    @ExceptionHandler(MethodArgumentNotValidException.class)
42
+    public ResponseEntity<?>
43
+    handleValidationError(MethodArgumentNotValidException manve, HttpServletRequest request) {
44
+        ErrorDetail errorDetail = new ErrorDetail();
45
+        Map<String, List<ValidationError>> errors = errorDetail.getErrors();
46
+
47
+        List<FieldError> fieldErrors =  manve.getBindingResult().getFieldErrors();
48
+        for(FieldError fe : fieldErrors) {
49
+            List<ValidationError> validationErrorList = errorDetail.getErrors().get(fe.getField());
50
+            if (validationErrorList == null) {
51
+                validationErrorList = new ArrayList<>();
52
+                errorDetail.getErrors().put(fe.getField(), validationErrorList);
53
+            }
54
+            ValidationError validationError = new ValidationError();
55
+            validationError.setCode(fe.getCode());
56
+            validationError.setMessage(messageSource.getMessage(fe, null));
57
+            validationErrorList.add(validationError);
58
+        }
59
+
60
+        return new ResponseEntity<>(errorDetail, HttpStatus.BAD_REQUEST);
61
+    }
62
+
63
+}

+ 7
- 0
src/main/java/io/zipcoder/tc_spring_poll_application/repositories/OptionRepository.java Wyświetl plik

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
+
6
+public interface OptionRepository extends CrudRepository<Option, Long> {
7
+}

+ 8
- 0
src/main/java/io/zipcoder/tc_spring_poll_application/repositories/PollRepository.java Wyświetl plik

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

+ 15
- 0
src/main/java/io/zipcoder/tc_spring_poll_application/repositories/VoteRepository.java Wyświetl plik

1
+package io.zipcoder.tc_spring_poll_application.repositories;
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
+    @Query(value = "SELECT v.* " +
9
+            "FROM Option o, Vote v " +
10
+            "WHERE o.POLL_ID = ?1 " +
11
+            "AND v.OPTION_ID = o.OPTION_ID", nativeQuery = true)
12
+
13
+    Iterable<Vote> findVotesByPoll(Long pollId);
14
+
15
+}

+ 89
- 0
src/main/resources/import.sql Wyświetl plik

1
+insert into poll (poll_id, question) values (1, 'What is your favorite primary color?');
2
+
3
+insert into option (option_value, poll_id) values ('Red', 1);
4
+insert into option (option_value, poll_id) values ('Blue', 1);
5
+insert into option (option_value, poll_id) values ('Yellow', 1);
6
+
7
+insert into poll (poll_id,  question) values (2, 'What is your favorite original Netflix series?');
8
+
9
+insert into option (option_value, poll_id) values ('Black Mirror', 2);
10
+insert into option (option_value, poll_id) values ('Voltron', 2);
11
+insert into option (option_value, poll_id) values ('Unbreakable Kimmy Schmidt', 2);
12
+
13
+insert into poll (poll_id,  question) values (3, 'What is your favorite candy?');
14
+
15
+insert into option (option_value, poll_id) values ('M&M''s', 3);
16
+insert into option (option_value, poll_id) values ('Skittles', 3);
17
+insert into option (option_value, poll_id) values ('Werther''s Originals', 3);
18
+
19
+insert into poll (poll_id,  question) values (4, 'What''s your favorite Gen 1 starter Pokemon?');
20
+
21
+insert into option (option_value, poll_id) values ('Bulbasaur', 4);
22
+insert into option (option_value, poll_id) values ('Squirtle', 4);
23
+insert into option (option_value, poll_id) values ('Charmander', 4);
24
+
25
+insert into poll (poll_id,  question) values (5, 'What''s your favorite Gen 2 starter Pokemon?');
26
+
27
+insert into option (option_value, poll_id) values ('Chikorita', 5);
28
+insert into option (option_value, poll_id) values ('Totodile', 5);
29
+insert into option (option_value, poll_id) values ('Cyndaquil', 5);
30
+
31
+insert into poll (poll_id,  question) values (6, 'What''s your favorite Gen 3 starter Pokemon?');
32
+
33
+insert into option (option_value, poll_id) values ('Treecko', 6);
34
+insert into option (option_value, poll_id) values ('Mudkip', 6);
35
+insert into option (option_value, poll_id) values ('Torchic', 6);
36
+
37
+insert into poll (poll_id,  question) values (7, 'What''s your favorite Gen 4 starter Pokemon?');
38
+
39
+insert into option (option_value, poll_id) values ('Turtwig', 7);
40
+insert into option (option_value, poll_id) values ('Piplup', 7);
41
+insert into option (option_value, poll_id) values ('Chimchar', 7);
42
+
43
+insert into poll (poll_id,  question) values (8, 'What''s your favorite Gen 5 starter Pokemon?');
44
+
45
+insert into option (option_value, poll_id) values ('Snivy', 8);
46
+insert into option (option_value, poll_id) values ('Oshawott', 8);
47
+insert into option (option_value, poll_id) values ('Tepig', 8);
48
+
49
+insert into poll (poll_id,  question) values (9, 'What''s your favorite Gen 6 starter Pokemon?');
50
+
51
+insert into option (option_value, poll_id) values ('Chespin', 9);
52
+insert into option (option_value, poll_id) values ('Froakie', 9);
53
+insert into option (option_value, poll_id) values ('Fennekin', 9);
54
+
55
+insert into poll (poll_id,  question) values (10, 'What''s your favorite Gen 7 starter Pokemon?');
56
+
57
+insert into option (option_value, poll_id) values ('Rowlet', 10);
58
+insert into option (option_value, poll_id) values ('Popplio', 10);
59
+insert into option (option_value, poll_id) values ('Litten', 10);
60
+
61
+insert into poll (poll_id,  question) values (11, 'What''s your favorite Let''s Go starter Pokemon?');
62
+
63
+insert into option (option_value, poll_id) values ('Pikachu', 11);
64
+insert into option (option_value, poll_id) values ('Eevee', 11);
65
+insert into option (option_value, poll_id) values ('Both', 11);
66
+
67
+insert into poll (poll_id,  question) values (12, 'Who is your favorite Belcher child?');
68
+
69
+insert into option (option_value, poll_id) values ('Tina', 12);
70
+insert into option (option_value, poll_id) values ('Gene', 12);
71
+insert into option (option_value, poll_id) values ('Louise', 12);
72
+
73
+insert into poll (poll_id,  question) values (13, 'What''s your favorite secondary color?');
74
+
75
+insert into option (option_value, poll_id) values ('Orange', 13);
76
+insert into option (option_value, poll_id) values ('Purple', 13);
77
+insert into option (option_value, poll_id) values ('Green', 13);
78
+
79
+insert into poll (poll_id,  question) values (14, 'What''s your favorite fruit?');
80
+
81
+insert into option (option_value, poll_id) values ('Apples', 14);
82
+insert into option (option_value, poll_id) values ('Bananas', 14);
83
+insert into option (option_value, poll_id) values ('Oranges', 14);
84
+
85
+insert into poll (poll_id,  question) values (15, 'What''s your favorite animal?');
86
+
87
+insert into option (option_value, poll_id) values ('Dog', 15);
88
+insert into option (option_value, poll_id) values ('Cat', 15);
89
+insert into option (option_value, poll_id) values ('Axolotl', 15);

+ 2
- 0
src/main/resources/messages.properties Wyświetl plik

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