Quellcode durchsuchen

Merge 18ab6b14446f0919f7066d513068cc14fda364fc into f91a622cc731197181dd1b1e4b17c9bcb450ae8a

CWinarski vor 8 Jahren
Ursprung
Commit
0512ee03ba
Es ist kein Account mit dieser Commiter-Email verbunden

+ 1
- 1
pom.xml Datei anzeigen

@@ -15,7 +15,7 @@
15 15
     </parent>
16 16
     <properties>
17 17
         <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
18
-        <start-class>io.zipcoder.tc_spring_poll_application.QuickPollApplication</start-class>
18
+        <start-class>io.zipcoder.springdemo.QuickPollApplication</start-class>
19 19
         <java.version>1.7</java.version>
20 20
     </properties>
21 21
     <dependencies>

+ 22
- 0
src/main/java/dtos/OptionCount.java Datei anzeigen

@@ -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 Datei anzeigen

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

+ 51
- 0
src/main/java/io/zipcoder/tc_spring_poll_application/controller/ComputeResultController.java Datei anzeigen

@@ -0,0 +1,51 @@
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.beans.factory.annotation.Autowired;
8
+import org.springframework.http.HttpStatus;
9
+import org.springframework.http.ResponseEntity;
10
+import org.springframework.web.bind.annotation.RequestMapping;
11
+import org.springframework.web.bind.annotation.RequestMethod;
12
+import org.springframework.web.bind.annotation.RequestParam;
13
+import org.springframework.web.bind.annotation.RestController;
14
+
15
+import java.util.HashMap;
16
+import java.util.Map;
17
+
18
+@RestController
19
+public class ComputeResultController {
20
+
21
+    private VoteRepository voteRepository;
22
+
23
+    @Autowired
24
+    public  ComputeResultController(VoteRepository voteRepository){
25
+        this.voteRepository = voteRepository;
26
+    }
27
+
28
+    @RequestMapping(value = "/computeresult", method = RequestMethod.GET)
29
+    public ResponseEntity<?> computeResult(@RequestParam Long pollId){ //requestparam annotation instructs SPring to retrieve the pollId value from a HTTP query
30
+        VoteResult voteResult = new VoteResult();
31
+        Iterable<Vote> allVotes = voteRepository.findVotesByPoll(pollId);
32
+
33
+        int totalVotes = 0;
34
+        Map<Long, OptionCount> tempMap = new HashMap<>();
35
+        for(Vote v : allVotes) {
36
+            totalVotes ++;
37
+            // Get the OptionCount corresponding to this Option
38
+            OptionCount optionCount = tempMap.get(v.getOption().getId());
39
+            if(optionCount == null) {
40
+                optionCount = new OptionCount();
41
+                optionCount.setOptionId(v.getOption().getId());
42
+                tempMap.put(v.getOption().getId(), optionCount);
43
+            }
44
+            optionCount.setCount(optionCount.getCount()+1);
45
+        }
46
+        voteResult.setTotalVotes(totalVotes);
47
+        voteResult.setResults(tempMap.values());
48
+
49
+        return new ResponseEntity<>(voteResult, HttpStatus.OK); //computes results sent to client using new response entity
50
+    }
51
+}

+ 79
- 0
src/main/java/io/zipcoder/tc_spring_poll_application/controller/PollController.java Datei anzeigen

@@ -0,0 +1,79 @@
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.Pageable;
9
+import org.springframework.http.HttpHeaders;
10
+import org.springframework.http.HttpStatus;
11
+import org.springframework.http.ResponseEntity;
12
+import org.springframework.web.bind.annotation.*;
13
+import org.springframework.web.servlet.support.ServletUriComponentsBuilder;
14
+
15
+import javax.validation.Valid;
16
+import java.net.URI;
17
+
18
+@RestController// marks entity as a controller following REST specs
19
+public class PollController {
20
+
21
+    private PollRepository pollRepository;
22
+
23
+    @Autowired //The @Autowired annotation allows you to skip configurations elsewhere of what to inject and just does it for you
24
+    public PollController(PollRepository pollRepository){
25
+        this.pollRepository = pollRepository;
26
+    }
27
+
28
+    @RequestMapping(value="/polls", method= RequestMethod.GET)//maps web requests to entities with the @RequestMapping
29
+    public ResponseEntity<Page<Poll>> getAllPolls(Pageable pageable) {
30
+        Page<Poll> allPolls = pollRepository.findAll(pageable); //essentially pages the data
31
+        return new ResponseEntity<>(allPolls, HttpStatus.OK);// returns paged data
32
+    }
33
+
34
+    @RequestMapping(value="/polls", method=RequestMethod.POST)
35
+    public ResponseEntity<?> createPoll(@RequestBody Poll poll) { //@RequestBody tells Spring that the entire request body needs to be converted to an instance of Poll
36
+        poll = pollRepository.save(poll);
37
+        HttpHeaders newHeaders = new HttpHeaders();
38
+
39
+        URI newPollUri = ServletUriComponentsBuilder //allows the client to have a way to know the uri of the created poll
40
+                .fromCurrentRequest()
41
+                .path("/{id}")
42
+                .buildAndExpand(poll.getId())
43
+                .toUri();
44
+                newHeaders.setLocation(newPollUri);
45
+        return new ResponseEntity<>(newHeaders, HttpStatus.CREATED);
46
+    }
47
+
48
+    @Valid
49
+    @RequestMapping(value="/polls/{pollId}", method=RequestMethod.GET)
50
+    public ResponseEntity<?> getPoll(@PathVariable Long pollId) {
51
+        verifyPoll(pollId);
52
+        Poll p = pollRepository.findOne(pollId);
53
+        return new ResponseEntity<> (p, HttpStatus.OK);
54
+    }
55
+
56
+    @Valid
57
+    @RequestMapping(value="/polls/{pollId}", method=RequestMethod.PUT)
58
+    public ResponseEntity<?> updatePoll(@RequestBody Poll poll, @PathVariable Long pollId) {
59
+        // Save the entity
60
+        verifyPoll(pollId);
61
+        Poll p = pollRepository.save(poll);
62
+        return new ResponseEntity<>(HttpStatus.OK);
63
+    }
64
+
65
+    @RequestMapping(value="/polls/{pollId}", method=RequestMethod.DELETE)
66
+    public ResponseEntity<?> deletePoll(@PathVariable Long pollId) {
67
+        verifyPoll(pollId);
68
+        pollRepository.delete(pollId);
69
+        return new ResponseEntity<>(HttpStatus.OK);
70
+    }
71
+
72
+    public void verifyPoll(Long pollId){
73
+        Poll poll = pollRepository.findOne(pollId);
74
+        if(poll == null){
75
+            throw new ResourceNotFoundException("The given poll id " + pollId + " does not exist!");
76
+        }
77
+    }
78
+
79
+}

+ 43
- 0
src/main/java/io/zipcoder/tc_spring_poll_application/controller/VoteController.java Datei anzeigen

@@ -0,0 +1,43 @@
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
+
13
+@RestController
14
+public class VoteController {
15
+
16
+    private VoteRepository voteRepository;
17
+
18
+    @Autowired
19
+    public VoteController(VoteRepository voteRepository) {
20
+        this.voteRepository = voteRepository;
21
+    }
22
+
23
+    @RequestMapping(value = "/polls/{pollId}/votes", method = RequestMethod.POST)
24
+    public ResponseEntity<?> createVote(@PathVariable Long pollId, @RequestBody Vote
25
+            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}").buildAndExpand(vote.getId()).toUri());
31
+        return new ResponseEntity<>(null, responseHeaders, HttpStatus.CREATED);
32
+    }
33
+
34
+    @RequestMapping(value="/polls/votes", method=RequestMethod.GET)
35
+    public Iterable<Vote> getAllVotes() {
36
+        return voteRepository.findAll();
37
+    }
38
+
39
+    @RequestMapping(value="/polls/{pollId}/votes", method=RequestMethod.GET)
40
+    public Iterable<Vote> getVote(@PathVariable Long pollId) {
41
+        return voteRepository.findVotesByPoll(pollId);
42
+    }
43
+}

+ 35
- 0
src/main/java/io/zipcoder/tc_spring_poll_application/domain/Option.java Datei anzeigen

@@ -0,0 +1,35 @@
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 // this means that a class can be mapped to a table. Just is a marker like Serializable
9
+public class Option {
10
+
11
+    @Id // specifies primary key of entity (primary key is a special column)
12
+    @GeneratedValue // configures the way of increment of the specified column (field)
13
+    @Column(name = "OPTION_ID")// specifies mapped column for a persistence property. Without this annotation the framework assumes the field's variable-name is the persistent property
14
+    private Long id;
15
+
16
+    @Column(name = "OPTION_VALUE")// specifies mapped column for persistence 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
+
35
+}

+ 50
- 0
src/main/java/io/zipcoder/tc_spring_poll_application/domain/Poll.java Datei anzeigen

@@ -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
+    @NotEmpty
18
+    @Column(name = "QUESTION")
19
+    private String question;
20
+
21
+    @Size(min=2, max = 6)
22
+    @OneToMany(cascade = CascadeType.ALL)// indicates that a Poll instance can contain zero or more Option instances. The CascadeType.All indicates that any database operations such as persist, remove, or merge on a Poll instance needs to be propagated to all related Option instances
23
+    @JoinColumn(name = "POLL_ID")// indicates this entity is the owner of the relationship. It has a key to the column with options
24
+    @OrderBy// orders by ASC default
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
+}

+ 31
- 0
src/main/java/io/zipcoder/tc_spring_poll_application/domain/Vote.java Datei anzeigen

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

+ 62
- 0
src/main/java/io/zipcoder/tc_spring_poll_application/error/ErrorDetail.java Datei anzeigen

@@ -0,0 +1,62 @@
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; // title of error condition
9
+    private int status; // HTTP status code for current request
10
+    private String detail; // short readable description of error
11
+    private long timeStamp; // time in milliseconds when error occurred
12
+    private String developerMessage; // detailed info as such exception class or trace
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 Datei anzeigen

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

+ 20
- 0
src/main/java/io/zipcoder/tc_spring_poll_application/exception/ResourceNotFoundException.java Datei anzeigen

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

+ 66
- 0
src/main/java/io/zipcoder/tc_spring_poll_application/exception/RestExceptionHandler.java Datei anzeigen

@@ -0,0 +1,66 @@
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
+
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
+        //make error detail object and fill it?
28
+        ErrorDetail errorDetail = new ErrorDetail();
29
+        errorDetail.setTitle("Resource Not Found");
30
+        errorDetail.setStatus(HttpStatus.NOT_FOUND.value());
31
+        errorDetail.setDetail(rnfe.getMessage());
32
+        errorDetail.setTimeStamp(new Date().getTime());
33
+        errorDetail.setDeveloperMessage(rnfe.getClass().getName());
34
+        return new ResponseEntity<>(errorDetail, null,  HttpStatus.NOT_FOUND);
35
+    }
36
+
37
+    @ExceptionHandler(MethodArgumentNotValidException.class)
38
+    public ResponseEntity<?> handleValicationError(MethodArgumentNotValidException manve, HttpServletRequest request){
39
+        ErrorDetail errorDetail = new ErrorDetail();
40
+        errorDetail.setTitle("Validation Failed");
41
+        errorDetail.setStatus(HttpStatus.BAD_REQUEST.value());
42
+        errorDetail.setDetail("Input validation failed");
43
+        errorDetail.setTimeStamp(new Date().getTime());
44
+        errorDetail.setDeveloperMessage(manve.getClass().getName());
45
+
46
+        String requestPath = (String) request.getAttribute("javax.servlet.error. request_uri");
47
+        if(requestPath == null) {
48
+            requestPath = request.getRequestURI();
49
+        }
50
+
51
+        List<FieldError> fieldErrors =  manve.getBindingResult().getFieldErrors();
52
+        for(FieldError fe : fieldErrors) {
53
+
54
+            List<ValidationError> validationErrorList = errorDetail.getErrors().get(fe.getField());
55
+            if(validationErrorList == null) {
56
+                validationErrorList = new ArrayList<>();
57
+                errorDetail.getErrors().put(fe.getField(), validationErrorList);
58
+            }
59
+            ValidationError validationError = new ValidationError();
60
+            validationError.setCode(fe.getCode());
61
+            validationError.setMessage(messageSource.getMessage(fe, null));
62
+            validationErrorList.add(validationError);
63
+        }
64
+        return new ResponseEntity<>(errorDetail, HttpStatus.BAD_REQUEST);
65
+    }
66
+}

+ 9
- 0
src/main/java/io/zipcoder/tc_spring_poll_application/repositories/OptionRepository.java Datei anzeigen

@@ -0,0 +1,9 @@
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
+    //these are DAOs pr Data Access Objects they provide abstraction for interacting with data stores
8
+    // ypu have usually one repository per domain object
9
+}

+ 10
- 0
src/main/java/io/zipcoder/tc_spring_poll_application/repositories/PollRepository.java Datei anzeigen

@@ -0,0 +1,10 @@
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
+    //these are DAOs pr Data Access Objects they provide abstraction for interacting with data stores
9
+    // ypu have usually one repository per domain object
10
+}

+ 16
- 0
src/main/java/io/zipcoder/tc_spring_poll_application/repositories/VoteRepository.java Datei anzeigen

@@ -0,0 +1,16 @@
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
+    //these are DAOs pr Data Access Objects they provide abstraction for interacting with data stores
9
+    // ypu have usually one repository per domain object
10
+
11
+    @Query(value = "SELECT v.* " +
12
+            "FROM Option o, Vote v " +
13
+            "WHERE o.POLL_ID = ?1 " +
14
+            "AND v.OPTION_ID = o.OPTION_ID", nativeQuery = true)
15
+    public Iterable<Vote> findVotesByPoll(Long pollId);
16
+}

+ 74
- 0
src/main/resources/import.sql Datei anzeigen

@@ -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, 'Purple', 1);
5
+
6
+ insert into poll (poll_id, question) values (2, 'What is your favorite car brand?');
7
+ insert into option (option_id, option_value, poll_id) values (4, 'Chevy', 2);
8
+ insert into option (option_id, option_value, poll_id) values (5, 'Subaru', 2);
9
+ insert into option (option_id, option_value, poll_id) values (6, 'Honda', 2);
10
+
11
+ insert into poll (poll_id, question) values (3, 'What is your favorite warframe?');
12
+ insert into option (option_id, option_value, poll_id) values (7, 'Saryn', 3);
13
+ insert into option (option_id, option_value, poll_id) values (8, 'Frost', 3);
14
+ insert into option (option_id, option_value, poll_id) values (9, 'Titania', 3);
15
+
16
+ insert into poll (poll_id, question) values (4, 'What is your favorite book genre?');
17
+ insert into option (option_id, option_value, poll_id) values (10, 'Sci-Fi', 4);
18
+ insert into option (option_id, option_value, poll_id) values (11, 'Fantasy', 4);
19
+ insert into option (option_id, option_value, poll_id) values (12, 'Drama', 4);
20
+
21
+ insert into poll (poll_id, question) values (5, 'What is your favorite movie?');
22
+ insert into option (option_id, option_value, poll_id) values (13, 'Ready Player One', 5);
23
+ insert into option (option_id, option_value, poll_id) values (14, 'Black Panther', 5);
24
+ insert into option (option_id, option_value, poll_id) values (15, 'Pacific Rim 2', 5);
25
+
26
+ insert into poll (poll_id, question) values (6, 'What is your favorite phone?');
27
+ insert into option (option_id, option_value, poll_id) values (16, 'Samsung s9', 6);
28
+ insert into option (option_id, option_value, poll_id) values (17, 'Lg v30', 6);
29
+ insert into option (option_id, option_value, poll_id) values (18, 'OnePlus 5T', 6);
30
+
31
+ insert into poll (poll_id, question) values (7, 'What is your favorite soda?');
32
+ insert into option (option_id, option_value, poll_id) values (19, 'Dr. Pepper', 7);
33
+ insert into option (option_id, option_value, poll_id) values (20, 'Coke', 7);
34
+ insert into option (option_id, option_value, poll_id) values (21, 'Pepsi', 7);
35
+
36
+ insert into poll (poll_id, question) values (8, 'What is your favorite console?');
37
+ insert into option (option_id, option_value, poll_id) values (22, 'PS4', 8);
38
+ insert into option (option_id, option_value, poll_id) values (23, 'Xbox One', 8);
39
+ insert into option (option_id, option_value, poll_id) values (24, 'Nintendo Switch', 8);
40
+
41
+ insert into poll (poll_id, question) values (9, 'What is your favorite music genre?');
42
+ insert into option (option_id, option_value, poll_id) values (25, 'Rock', 9);
43
+ insert into option (option_id, option_value, poll_id) values (26, 'Edm', 9);
44
+ insert into option (option_id, option_value, poll_id) values (27, 'Pop', 9);
45
+
46
+ insert into poll (poll_id, question) values (10, 'What is your favorite pet?');
47
+ insert into option (option_id, option_value, poll_id) values (28, 'Dog', 10);
48
+ insert into option (option_id, option_value, poll_id) values (29, 'Cat', 10);
49
+ insert into option (option_id, option_value, poll_id) values (30, 'Bird', 10);
50
+
51
+ insert into poll (poll_id, question) values (11, 'What is your favorite monstercat artist?');
52
+ insert into option (option_id, option_value, poll_id) values (31, 'Conro', 11);
53
+ insert into option (option_id, option_value, poll_id) values (32, 'Muzzy', 11);
54
+ insert into option (option_id, option_value, poll_id) values (33, 'Kuuro', 11);
55
+
56
+ insert into poll (poll_id, question) values (12, 'What is your favorite computer brand?');
57
+ insert into option (option_id, option_value, poll_id) values (34, 'HP', 12);
58
+ insert into option (option_id, option_value, poll_id) values (35, 'Apple', 12);
59
+ insert into option (option_id, option_value, poll_id) values (36, 'Purple', 12);
60
+
61
+ insert into poll (poll_id, question) values (13, 'What is your favorite gaming brand?');
62
+ insert into option (option_id, option_value, poll_id) values (37, 'Logitech', 13);
63
+ insert into option (option_id, option_value, poll_id) values (38, 'Corsair', 13);
64
+ insert into option (option_id, option_value, poll_id) values (39, 'HyperX', 13);
65
+
66
+ insert into poll (poll_id, question) values (14, 'What is your favorite food?');
67
+ insert into option (option_id, option_value, poll_id) values (40, 'Sushi', 14);
68
+ insert into option (option_id, option_value, poll_id) values (41, 'Pizza', 14);
69
+ insert into option (option_id, option_value, poll_id) values (42, 'Fries', 14);
70
+
71
+ insert into poll (poll_id, question) values (15, 'What is your favorite chip brand?');
72
+ insert into option (option_id, option_value, poll_id) values (43, 'Doritos', 15);
73
+ insert into option (option_id, option_value, poll_id) values (44, 'Lays', 15);
74
+ insert into option (option_id, option_value, poll_id) values (45, 'Herrs', 15);

+ 2
- 0
src/main/resources/messages.properties Datei anzeigen

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