Explorar el Código

Merge e93c539bc9fc7a9d91d2339a0c931656795cfdac into f91a622cc731197181dd1b1e4b17c9bcb450ae8a

Anthony Jordan hace 8 años
padre
commit
d67875d553
Ninguna cuenta está vinculada al correo electrónico del colaborador

+ 5
- 0
pom.xml Ver fichero

@@ -37,6 +37,11 @@
37 37
             <artifactId>hsqldb</artifactId>
38 38
             <scope>runtime</scope>
39 39
         </dependency>
40
+        <dependency>
41
+            <groupId>com.h2database</groupId>
42
+            <artifactId>h2</artifactId>
43
+            <scope>runtime</scope>
44
+        </dependency>
40 45
 
41 46
         <dependency>
42 47
             <groupId>javax.inject</groupId>

+ 22
- 0
src/main/java/dtos/OptionCount.java Ver fichero

@@ -0,0 +1,22 @@
1
+package 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/dtos/VoteResult.java Ver fichero

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

+ 62
- 0
src/main/java/dtos/error/ErrorDetail.java Ver fichero

@@ -0,0 +1,62 @@
1
+package dtos.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
+}

+ 65
- 0
src/main/java/dtos/error/RestExceptionHandler.java Ver fichero

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

+ 22
- 0
src/main/java/dtos/error/ValidationError.java Ver fichero

@@ -0,0 +1,22 @@
1
+package dtos.error;
2
+
3
+public class ValidationError {
4
+    private String code;
5
+    private 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
+}

+ 45
- 0
src/main/java/io/zipcoder/tc_spring_poll_application/controller/ComputeResultController.java Ver fichero

@@ -0,0 +1,45 @@
1
+package io.zipcoder.tc_spring_poll_application.controller;
2
+
3
+import dtos.OptionCount;
4
+import dtos.VoteResult;
5
+import io.zipcoder.tc_spring_poll_application.domain.Vote;
6
+import io.zipcoder.tc_spring_poll_application.repositories.VoteRepository;
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
+import javax.inject.Inject;
15
+import java.util.HashMap;
16
+import java.util.Map;
17
+
18
+@RestController
19
+public class ComputeResultController {
20
+    @Inject
21
+    private VoteRepository voteRepository;
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
+        int totalVotes = 0;
29
+        Map<Long, OptionCount> tempMap = new HashMap<Long, OptionCount>();
30
+        for(Vote v : allVotes) {
31
+            totalVotes ++;
32
+            // Get the OptionCount corresponding to this Option
33
+            OptionCount optionCount = tempMap.get(v.getOption().getId());
34
+            if(optionCount == null) {
35
+                optionCount = new OptionCount();
36
+                optionCount.setOptionId(v.getOption().getId());
37
+                tempMap.put(v.getOption().getId(), optionCount);
38
+            }
39
+            optionCount.setCount(optionCount.getCount()+1);
40
+        }
41
+        voteResult.setTotalVotes(totalVotes);
42
+        voteResult.setResults(tempMap.values());
43
+        return new ResponseEntity<VoteResult>(voteResult, HttpStatus.OK);
44
+    }
45
+}

+ 75
- 0
src/main/java/io/zipcoder/tc_spring_poll_application/controller/PollController.java Ver fichero

@@ -0,0 +1,75 @@
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.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.inject.Inject;
14
+import javax.validation.Valid;
15
+import java.net.URI;
16
+
17
+@RestController
18
+public class PollController {
19
+
20
+    @Inject
21
+    private PollRepository pollRepository;
22
+
23
+    @Autowired
24
+    PollController(PollRepository pollRepository){
25
+        this.pollRepository = pollRepository;
26
+    }
27
+
28
+    @RequestMapping(value="/polls", method= RequestMethod.GET)
29
+    public ResponseEntity<Iterable<Poll>> getAllPolls() {
30
+        Iterable<Poll> allPolls = pollRepository.findAll();
31
+        return new ResponseEntity<>(allPolls, HttpStatus.OK);
32
+    }
33
+
34
+    @RequestMapping(value="/polls/{pollId}", method=RequestMethod.GET)
35
+    public ResponseEntity<?> getPoll(@PathVariable Long pollId) {
36
+        verifyPoll(pollId);
37
+        Poll p = pollRepository.findOne(pollId);
38
+        return new ResponseEntity<> (p, HttpStatus.OK);
39
+    }
40
+
41
+    @Valid
42
+    @RequestMapping(value="/polls", method=RequestMethod.POST)
43
+    public ResponseEntity<?> createPoll(@RequestBody Poll poll) {
44
+        poll = pollRepository.save(poll);
45
+        URI newPollUri = ServletUriComponentsBuilder
46
+                .fromCurrentRequest()
47
+                .path("/{id}")
48
+                .buildAndExpand(poll.getId())
49
+                .toUri();
50
+        HttpHeaders location = new HttpHeaders();
51
+        location.setLocation(newPollUri);
52
+        return new ResponseEntity<>(location, HttpStatus.CREATED);
53
+    }
54
+
55
+    @RequestMapping(value="/polls/{pollId}", method=RequestMethod.PUT)
56
+    public ResponseEntity<?> updatePoll(@RequestBody Poll poll, @PathVariable Long pollId) {
57
+        // Save the entity
58
+        verifyPoll(pollId);
59
+        Poll p = pollRepository.save(poll);
60
+        return new ResponseEntity<>(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){
71
+        if (pollRepository.findOne(pollId) == null){
72
+            throw new ResourceNotFoundException();
73
+        }
74
+    }
75
+}

+ 46
- 0
src/main/java/io/zipcoder/tc_spring_poll_application/controller/VoteController.java Ver fichero

@@ -0,0 +1,46 @@
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.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
+import javax.validation.Valid;
14
+
15
+@RestController
16
+public class VoteController {
17
+    @Inject
18
+    private VoteRepository voteRepository;
19
+
20
+    @Autowired
21
+    public VoteController(VoteRepository voteRepository) {
22
+        this.voteRepository = voteRepository;
23
+    }
24
+
25
+    @Valid
26
+    @RequestMapping(value = "/polls/{pollId}/votes", method = RequestMethod.POST)
27
+    public ResponseEntity<?> createVote(@PathVariable Long pollId, @RequestBody Vote
28
+            vote) {
29
+        vote = voteRepository.save(vote);
30
+        // Set the headers for the newly created resource
31
+        HttpHeaders responseHeaders = new HttpHeaders();
32
+        responseHeaders.setLocation(ServletUriComponentsBuilder.
33
+                fromCurrentRequest().path("/{id}").buildAndExpand(vote.getId()).toUri());
34
+        return new ResponseEntity<>(null, responseHeaders, HttpStatus.CREATED);
35
+    }
36
+
37
+    @RequestMapping(value="/polls/votes", method=RequestMethod.GET)
38
+    public Iterable<Vote> getAllVotes() {
39
+        return voteRepository.findAll();
40
+    }
41
+
42
+    @RequestMapping(value="/polls/{pollId}/votes", method=RequestMethod.GET)
43
+    public Iterable<Vote> getVote(@PathVariable Long pollId) {
44
+        return voteRepository.findVotesByPoll(pollId);
45
+    }
46
+}

+ 33
- 0
src/main/java/io/zipcoder/tc_spring_poll_application/domain/Option.java Ver fichero

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

+ 50
- 0
src/main/java/io/zipcoder/tc_spring_poll_application/domain/Poll.java Ver fichero

@@ -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 Ver fichero

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

+ 18
- 0
src/main/java/io/zipcoder/tc_spring_poll_application/exception/ResourceNotFoundException.java Ver fichero

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

+ 7
- 0
src/main/java/io/zipcoder/tc_spring_poll_application/repositories/OptionRepository.java Ver fichero

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

+ 7
- 0
src/main/java/io/zipcoder/tc_spring_poll_application/repositories/PollRepository.java Ver fichero

@@ -0,0 +1,7 @@
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.PagingAndSortingRepository;
5
+
6
+public interface PollRepository extends PagingAndSortingRepository<Poll, Long> {
7
+}

+ 13
- 0
src/main/java/io/zipcoder/tc_spring_poll_application/repositories/VoteRepository.java Ver fichero

@@ -0,0 +1,13 @@
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
+    public Iterable<Vote> findVotesByPoll(Long pollId);
13
+}

+ 2
- 0
src/main/resources/application.properties Ver fichero

@@ -0,0 +1,2 @@
1
+spring.h2.console.enabled=true
2
+spring.h2.console.path=/h2-console

+ 88
- 0
src/main/resources/import.sql Ver fichero

@@ -0,0 +1,88 @@
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, 'Black', 1);
4
+insert into option (option_id, option_value, poll_id) values (3, 'Green', 1);
5
+
6
+
7
+insert into poll (poll_id, question) values (2, 'What is your favorite band?');
8
+insert into option (option_id, option_value, poll_id) values (4, 'Tool', 2);
9
+insert into option (option_id, option_value, poll_id) values (5, 'Carpenter Brut', 2);
10
+insert into option (option_id, option_value, poll_id) values (6, 'Fleetwood Mac', 2);
11
+
12
+
13
+insert into poll (poll_id, question) values (3, 'What is your favorite tv show?');
14
+insert into option (option_id, option_value, poll_id) values (7, 'Altered Carbon', 3);
15
+insert into option (option_id, option_value, poll_id) values (8, 'My Little Pony', 3);
16
+insert into option (option_id, option_value, poll_id) values (9, 'Game of Thrones', 3);
17
+
18
+
19
+insert into poll (poll_id, question) values (4, 'What is your favorite flower?');
20
+insert into option (option_id, option_value, poll_id) values (10, 'Lilly', 4);
21
+insert into option (option_id, option_value, poll_id) values (11, 'Rose', 4);
22
+insert into option (option_id, option_value, poll_id) values (12, 'Tulip', 4);
23
+
24
+
25
+insert into poll (poll_id, question) values (5, 'What is your favorite type of tree?');
26
+insert into option (option_id, option_value, poll_id) values (13, 'Oak', 5);
27
+insert into option (option_id, option_value, poll_id) values (14, 'Birch', 5);
28
+insert into option (option_id, option_value, poll_id) values (15, 'Willow', 5);
29
+
30
+
31
+insert into poll (poll_id, question) values (6, 'What is your favorite type of alcohol?');
32
+insert into option (option_id, option_value, poll_id) values (16, 'Whiskey', 6);
33
+insert into option (option_id, option_value, poll_id) values (17, 'Vodka', 6);
34
+insert into option (option_id, option_value, poll_id) values (18, 'Gin', 6);
35
+
36
+
37
+insert into poll (poll_id, question) values (7, 'What is your favorite pizza topping?');
38
+insert into option (option_id, option_value, poll_id) values (19, 'Pineapple', 7);
39
+insert into option (option_id, option_value, poll_id) values (20, 'Pepperoni', 7);
40
+insert into option (option_id, option_value, poll_id) values (21, 'Chicken', 7);
41
+
42
+
43
+insert into poll (poll_id, question) values (8, 'What is your favorite cheese?');
44
+insert into option (option_id, option_value, poll_id) values (22, 'Brie', 8);
45
+insert into option (option_id, option_value, poll_id) values (23, 'Pepper Jack', 8);
46
+insert into option (option_id, option_value, poll_id) values (24, 'American', 8);
47
+
48
+
49
+insert into poll (poll_id, question) values (9, 'What is your favorite snimsl?');
50
+insert into option (option_id, option_value, poll_id) values (25, 'Cat', 9);
51
+insert into option (option_id, option_value, poll_id) values (26, 'Tiger', 9);
52
+insert into option (option_id, option_value, poll_id) values (27, 'Pony', 9);
53
+
54
+
55
+insert into poll (poll_id, question) values (10, 'What is your favorite Lovecraft monster?');
56
+insert into option (option_id, option_value, poll_id) values (28, 'Cthulu', 10);
57
+insert into option (option_id, option_value, poll_id) values (29, 'Azathoth', 10);
58
+insert into option (option_id, option_value, poll_id) values (30, 'Dagon', 10);
59
+
60
+
61
+insert into poll (poll_id, question) values (11, 'What is your favorite Roman Emperor?');
62
+insert into option (option_id, option_value, poll_id) values (31, 'Tiberius', 11);
63
+insert into option (option_id, option_value, poll_id) values (32, 'Caligula', 11);
64
+insert into option (option_id, option_value, poll_id) values (33, 'Nero', 11);
65
+
66
+
67
+insert into poll (poll_id, question) values (12, 'What is your favorite Batman villian?');
68
+insert into option (option_id, option_value, poll_id) values (34, 'Joker', 12);
69
+insert into option (option_id, option_value, poll_id) values (35, 'Bane', 12);
70
+insert into option (option_id, option_value, poll_id) values (36, 'Clayface', 12);
71
+
72
+
73
+insert into poll (poll_id, question) values (13, 'What is your favorite American President?');
74
+insert into option (option_id, option_value, poll_id) values (37, 'Donald Trumo', 13);
75
+insert into option (option_id, option_value, poll_id) values (38, 'William Taft', 13);
76
+insert into option (option_id, option_value, poll_id) values (39, 'William Henry Harrison', 13);
77
+
78
+
79
+insert into poll (poll_id, question) values (14, 'What is your favorite phone brand?');
80
+insert into option (option_id, option_value, poll_id) values (40, 'iPhone', 14);
81
+insert into option (option_id, option_value, poll_id) values (41, 'Android', 14);
82
+insert into option (option_id, option_value, poll_id) values (42, 'Windows', 14);
83
+
84
+
85
+insert into poll (poll_id, question) values (15, 'What is your favorite landmark?');
86
+insert into option (option_id, option_value, poll_id) values (43, 'Pyramids', 15);
87
+insert into option (option_id, option_value, poll_id) values (44, 'Hanging Gardens', 15);
88
+insert into option (option_id, option_value, poll_id) values (45, 'Colossus of Rhodes', 15);

+ 2
- 0
src/main/resources/messages.properties Ver fichero

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