Просмотр исходного кода

Merge 25d00d22e3b60ade381668c7696c67f0b16d7d8c into f91a622cc731197181dd1b1e4b17c9bcb450ae8a

vvg3 8 лет назад
Родитель
Сommit
69eed27212
Аккаунт пользователя с таким Email не найден
17 измененных файлов: 596 добавлений и 0 удалений
  1. 29
    0
      src/main/java/io/zipcoder/tc_spring_poll_application/controller/ComputeResultController.java
  2. 71
    0
      src/main/java/io/zipcoder/tc_spring_poll_application/controller/PollController.java
  3. 41
    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. 51
    0
      src/main/java/io/zipcoder/tc_spring_poll_application/domain/Poll.java
  6. 33
    0
      src/main/java/io/zipcoder/tc_spring_poll_application/domain/Vote.java
  7. 24
    0
      src/main/java/io/zipcoder/tc_spring_poll_application/dtos/OptionCount.java
  8. 25
    0
      src/main/java/io/zipcoder/tc_spring_poll_application/dtos/VoteResult.java
  9. 65
    0
      src/main/java/io/zipcoder/tc_spring_poll_application/dtos/error/ErrorDetail.java
  10. 25
    0
      src/main/java/io/zipcoder/tc_spring_poll_application/dtos/error/ValidationError.java
  11. 22
    0
      src/main/java/io/zipcoder/tc_spring_poll_application/exception/ResourceNotFoundException.java
  12. 69
    0
      src/main/java/io/zipcoder/tc_spring_poll_application/handler/RestExceptionHandler.java
  13. 8
    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. 74
    0
      src/main/resources/import.sql
  17. 2
    0
      src/main/resources/messages.properties

+ 29
- 0
src/main/java/io/zipcoder/tc_spring_poll_application/controller/ComputeResultController.java Просмотреть файл

@@ -0,0 +1,29 @@
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.repositories.VoteRepository;
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
+import javax.inject.Inject;
14
+
15
+@RestController
16
+public class ComputeResultController {
17
+
18
+    @Inject
19
+    private VoteRepository voteRepository;
20
+
21
+    @RequestMapping(value = "/computeresult", method = RequestMethod.GET)
22
+    public ResponseEntity<?> computeResult(@RequestParam Long pollId) {
23
+        VoteResult voteResult = new VoteResult();
24
+        Iterable<Vote> allVotes = voteRepository.findVotesByPoll(pollId);
25
+
26
+        return new ResponseEntity<VoteResult>(voteResult, HttpStatus.OK);
27
+    }
28
+
29
+}

+ 71
- 0
src/main/java/io/zipcoder/tc_spring_poll_application/controller/PollController.java Просмотреть файл

@@ -0,0 +1,71 @@
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.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
+
13
+import javax.inject.Inject;
14
+import javax.validation.Valid;
15
+import java.net.URI;
16
+
17
+
18
+@RestController
19
+public class PollController {
20
+
21
+    @Inject
22
+    private PollRepository pollRepository;
23
+
24
+    @RequestMapping(value="/polls", method= RequestMethod.GET)
25
+    public ResponseEntity<Iterable<Poll>> getAllPolls() {
26
+        Iterable<Poll> allPolls = pollRepository.findAll();
27
+        return new ResponseEntity<>(allPolls, HttpStatus.OK);
28
+    }
29
+
30
+    @RequestMapping(value="/polls/{pollId}", method=RequestMethod.GET)
31
+    public ResponseEntity<?> getPoll(@PathVariable Long pollId) {
32
+        Poll p = pollRepository.findOne(pollId);
33
+        return new ResponseEntity<>(p, HttpStatus.OK);
34
+    }
35
+
36
+    @RequestMapping(value="/polls", method= RequestMethod.POST)
37
+    public ResponseEntity<?> createPoll(@Valid @RequestBody Poll poll) {
38
+        poll = pollRepository.save(poll);
39
+
40
+        HttpHeaders headers = new HttpHeaders();
41
+        URI newPollUri = ServletUriComponentsBuilder
42
+                .fromCurrentRequest()
43
+                .path("/{id}")
44
+                .buildAndExpand(poll.getId())
45
+                .toUri();
46
+
47
+        headers.setLocation(newPollUri);
48
+
49
+        return new ResponseEntity<>(null, headers, HttpStatus.CREATED);
50
+    }
51
+
52
+    @RequestMapping(value="/polls/{pollId}", method=RequestMethod.PUT)
53
+    public ResponseEntity<?> updatePoll(@Valid @RequestBody Poll poll, @PathVariable Long 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
+        pollRepository.delete(pollId);
61
+        return new ResponseEntity<>(HttpStatus.OK);
62
+    }
63
+
64
+    public void verifyPoll(Long pollId) {
65
+        Poll poll = pollRepository.findOne(pollId);
66
+        if (poll == null) {
67
+            throw new ResourceNotFoundException("Poll with id" + pollId + " not found");
68
+        }
69
+    }
70
+
71
+}

+ 41
- 0
src/main/java/io/zipcoder/tc_spring_poll_application/controller/VoteController.java Просмотреть файл

@@ -0,0 +1,41 @@
1
+package io.zipcoder.tc_spring_poll_application.controller;
2
+
3
+
4
+import io.zipcoder.tc_spring_poll_application.domain.Vote;
5
+import io.zipcoder.tc_spring_poll_application.repositories.VoteRepository;
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
+import javax.inject.Inject;
13
+
14
+@RestController
15
+public class VoteController {
16
+    @Inject
17
+    private VoteRepository voteRepository;
18
+
19
+    @RequestMapping(value="/polls/{pollId}/votes", method= RequestMethod.POST)
20
+    public ResponseEntity<?> createVote(@PathVariable Long pollId, @RequestBody Vote vote) {
21
+        vote = voteRepository.save(vote);
22
+        HttpHeaders responseHeaders = new HttpHeaders();
23
+
24
+        responseHeaders.setLocation(ServletUriComponentsBuilder.fromCurrentRequest().path("/{id}")
25
+        .buildAndExpand(vote.getId()).toUri());
26
+
27
+        return new ResponseEntity<>(null, responseHeaders, HttpStatus.CREATED);
28
+    }
29
+
30
+    @RequestMapping(value="polls/votes", method=RequestMethod.GET)
31
+    public Iterable<Vote> getAllVotes() {
32
+        return voteRepository.findAll();
33
+    }
34
+
35
+    @RequestMapping(value="polls/{pollId}/votes", method=RequestMethod.GET)
36
+    public Iterable<Vote> getVote(@PathVariable Long pollId) {
37
+        return voteRepository.findVotesByPoll(pollId);
38
+    }
39
+
40
+
41
+}

+ 34
- 0
src/main/java/io/zipcoder/tc_spring_poll_application/domain/Option.java Просмотреть файл

@@ -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 String getValue() {
24
+        return value;
25
+    }
26
+
27
+    public void setId(long id) {
28
+        this.id = id;
29
+    }
30
+
31
+    public void setValue(String value) {
32
+        this.value = value;
33
+    }
34
+}

+ 51
- 0
src/main/java/io/zipcoder/tc_spring_poll_application/domain/Poll.java Просмотреть файл

@@ -0,0 +1,51 @@
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
+
28
+    public long getId() {
29
+        return id;
30
+    }
31
+
32
+    public void setId(long id) {
33
+        this.id = id;
34
+    }
35
+
36
+    public String getQuestion() {
37
+        return question;
38
+    }
39
+
40
+    public void setQuestion(String question) {
41
+        this.question = question;
42
+    }
43
+
44
+    public Set<Option> getOptions() {
45
+        return options;
46
+    }
47
+
48
+    public void setOptions(Set<Option> options) {
49
+        this.options = options;
50
+    }
51
+}

+ 33
- 0
src/main/java/io/zipcoder/tc_spring_poll_application/domain/Vote.java Просмотреть файл

@@ -0,0 +1,33 @@
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
+
18
+    public long getId() {
19
+        return id;
20
+    }
21
+
22
+    public void setId(long id) {
23
+        this.id = id;
24
+    }
25
+
26
+    public Option getOption() {
27
+        return option;
28
+    }
29
+
30
+    public void setOption(Option option) {
31
+        this.option = option;
32
+    }
33
+}

+ 24
- 0
src/main/java/io/zipcoder/tc_spring_poll_application/dtos/OptionCount.java Просмотреть файл

@@ -0,0 +1,24 @@
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
+
24
+}

+ 25
- 0
src/main/java/io/zipcoder/tc_spring_poll_application/dtos/VoteResult.java Просмотреть файл

@@ -0,0 +1,25 @@
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
+}

+ 65
- 0
src/main/java/io/zipcoder/tc_spring_poll_application/dtos/error/ErrorDetail.java Просмотреть файл

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

+ 25
- 0
src/main/java/io/zipcoder/tc_spring_poll_application/dtos/error/ValidationError.java Просмотреть файл

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

+ 22
- 0
src/main/java/io/zipcoder/tc_spring_poll_application/exception/ResourceNotFoundException.java Просмотреть файл

@@ -0,0 +1,22 @@
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
+    }
12
+
13
+    public ResourceNotFoundException(String message) {
14
+        super(message);
15
+    }
16
+
17
+    public ResourceNotFoundException(String message, Throwable cause) {
18
+        super(message, cause);
19
+    }
20
+
21
+
22
+}

+ 69
- 0
src/main/java/io/zipcoder/tc_spring_poll_application/handler/RestExceptionHandler.java Просмотреть файл

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

+ 8
- 0
src/main/java/io/zipcoder/tc_spring_poll_application/repositories/OptionRepository.java Просмотреть файл

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

+ 8
- 0
src/main/java/io/zipcoder/tc_spring_poll_application/repositories/PollRepository.java Просмотреть файл

@@ -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
+
6
+public interface PollRepository extends CrudRepository<Poll, Long> {
7
+
8
+}

+ 15
- 0
src/main/java/io/zipcoder/tc_spring_poll_application/repositories/VoteRepository.java Просмотреть файл

@@ -0,0 +1,15 @@
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
+
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
+}

+ 74
- 0
src/main/resources/import.sql Просмотреть файл

@@ -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, 'Orange', 1);
4
+insert into option (option_id, option_value, poll_id) values (3, 'Yellow', 1);
5
+
6
+insert into poll (poll_id, question) values (2, 'What is your favorite movie?');
7
+insert into option (option_id, option_value, poll_id) values (4, 'Pulp Fiction', 2);
8
+insert into option (option_id, option_value, poll_id) values (5, 'In Bruges', 2);
9
+insert into option (option_id, option_value, poll_id) values (6, 'Rounders', 2);
10
+
11
+insert into poll (poll_id, question) values (3, 'What is your favorite book?');
12
+insert into option (option_id, option_value, poll_id) values (7, 'Game of Thrones', 3);
13
+insert into option (option_id, option_value, poll_id) values (8, 'The Kingkiller Chronicles', 3);
14
+insert into option (option_id, option_value, poll_id) values (9, 'The Dictionary', 3);
15
+
16
+insert into poll (poll_id, question) values (4, 'What is your favorite TV show?');
17
+insert into option (option_id, option_value, poll_id) values (10, 'Atlanta', 4);
18
+insert into option (option_id, option_value, poll_id) values (11, 'Billions', 4);
19
+insert into option (option_id, option_value, poll_id) values (12, 'Survivor', 4);
20
+
21
+insert into poll (poll_id, question) values (5, 'What is the best lunch spot?');
22
+insert into option (option_id, option_value, poll_id) values (13, 'Mimis', 5);
23
+insert into option (option_id, option_value, poll_id) values (14, 'Bennis', 5);
24
+insert into option (option_id, option_value, poll_id) values (15, 'Qdoba', 5);
25
+
26
+insert into poll (poll_id, question) values (6, 'What is your favorite sport?');
27
+insert into option (option_id, option_value, poll_id) values (16, 'Basketball', 6);
28
+insert into option (option_id, option_value, poll_id) values (17, 'Football', 6);
29
+insert into option (option_id, option_value, poll_id) values (18, 'Boogie Boarding', 6);
30
+
31
+insert into poll (poll_id, question) values (7, 'Where should Joe sleep?');
32
+insert into option (option_id, option_value, poll_id) values (19, 'Sisters home', 7);
33
+insert into option (option_id, option_value, poll_id) values (20, 'Original home', 7);
34
+insert into option (option_id, option_value, poll_id) values (21, 'Zip Code couch', 7);
35
+
36
+insert into poll (poll_id, question) values (8, 'When should you get coffee?');
37
+insert into option (option_id, option_value, poll_id) values (22, 'Past', 8);
38
+insert into option (option_id, option_value, poll_id) values (23, 'Present', 8);
39
+insert into option (option_id, option_value, poll_id) values (24, 'Future', 8);
40
+
41
+insert into poll (poll_id, question) values (9, 'How many polls are left to create?');
42
+insert into option (option_id, option_value, poll_id) values (25, 'One', 9);
43
+insert into option (option_id, option_value, poll_id) values (26, 'More', 9);
44
+insert into option (option_id, option_value, poll_id) values (27, 'So many', 9);
45
+
46
+insert into poll (poll_id, question) values (10, 'Who is a former child actor?');
47
+insert into option (option_id, option_value, poll_id) values (28, 'Kay', 10);
48
+insert into option (option_id, option_value, poll_id) values (29, 'Lawrence', 10);
49
+insert into option (option_id, option_value, poll_id) values (30, 'Joe', 10);
50
+
51
+insert into poll (poll_id, question) values (11, 'Which company would you like to work for?');
52
+insert into option (option_id, option_value, poll_id) values (31, 'McDonalds', 11);
53
+insert into option (option_id, option_value, poll_id) values (32, 'Burger King', 11);
54
+insert into option (option_id, option_value, poll_id) values (33, 'Taco Bell', 11);
55
+
56
+insert into poll (poll_id, question) values (12, 'Why?');
57
+insert into option (option_id, option_value, poll_id) values (34, 'Because', 12);
58
+insert into option (option_id, option_value, poll_id) values (35, 'Idk', 12);
59
+insert into option (option_id, option_value, poll_id) values (36, 'Why not?', 12);
60
+
61
+insert into poll (poll_id, question) values (13, 'Do you enjoy polls?');
62
+insert into option (option_id, option_value, poll_id) values (37, 'Yes', 13);
63
+insert into option (option_id, option_value, poll_id) values (38, 'No', 13);
64
+insert into option (option_id, option_value, poll_id) values (39, 'Maybe', 13);
65
+
66
+insert into poll (poll_id, question) values (14, 'Chicken on a...?');
67
+insert into option (option_id, option_value, poll_id) values (40, 'Biscuit', 14);
68
+insert into option (option_id, option_value, poll_id) values (41, 'Buttermilk pancake', 14);
69
+insert into option (option_id, option_value, poll_id) values (42, 'Cheerio', 14);
70
+
71
+insert into poll (poll_id, question) values (15, 'How do you like your eggs?');
72
+insert into option (option_id, option_value, poll_id) values (43, 'Shaken', 15);
73
+insert into option (option_id, option_value, poll_id) values (44, 'Stirred', 15);
74
+insert into option (option_id, option_value, poll_id) values (45, 'Scrambled', 15);

+ 2
- 0
src/main/resources/messages.properties Просмотреть файл

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