Brandon Defrancis 5 년 전
부모
커밋
f3ae07fe90

+ 2
- 2
README.md 파일 보기

@@ -1,9 +1,9 @@
1
-# Poll Application
1
+****# Poll Application
2 2
 * **Purpose**
3 3
 	* to demonstrate the basic functionality of the [Spring Framework](https://spring.io/)
4 4
 	* to demonstrate API testing via [Postman](https://chrome.google.com/webstore/detail/postman/fhbjgbiflinjbdggehcddcbncdddomop?hl=en)
5 5
 
6
-# Part 1 - Domain Implementation
6
+# Part  1 - Domain Implementation
7 7
 
8 8
 * _Domain objects_ are the backbone for an application and contain the [business logic](https://en.wikipedia.org/wiki/Business_logic).
9 9
 * Create a sub package of `io.zipcoder.tc_spring_poll_application` named `domain`.

+ 22
- 0
src/main/java/dtos/OptionCount.java 파일 보기

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

+ 23
- 0
src/main/java/dtos/VoteResult.java 파일 보기

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

+ 33
- 0
src/main/java/io/zipcoder/tc_spring_poll_application/controller/ComputeResultController.java 파일 보기

@@ -0,0 +1,33 @@
1
+package io.zipcoder.tc_spring_poll_application.controller;
2
+
3
+import dtos.VoteResult;
4
+import io.zipcoder.tc_spring_poll_application.controller.VoteController;
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
+@RestController
16
+public class ComputeResultController {
17
+
18
+    private VoteRepository voteRepository;
19
+
20
+    @Autowired
21
+    public ComputeResultController(VoteRepository voteRepository) {
22
+        this.voteRepository = voteRepository;
23
+    }
24
+
25
+    @RequestMapping(value = "/computeresult", method = RequestMethod.GET)
26
+    public ResponseEntity<?> computeResult(@RequestParam Long pollId) {
27
+        VoteResult voteResult = new VoteResult();
28
+        Iterable<Vote> allVotes = voteRepository.findVotesByPoll(pollId);
29
+
30
+        //TODO: Implement algorithm to count votes
31
+        return new ResponseEntity<VoteResult>(voteResult, HttpStatus.OK);
32
+    }
33
+}

+ 73
- 0
src/main/java/io/zipcoder/tc_spring_poll_application/controller/PollController.java 파일 보기

@@ -0,0 +1,73 @@
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.validation.Valid;
14
+import java.net.URI;
15
+
16
+@RestController
17
+public class PollController {
18
+
19
+    private PollRepository pollRepository;
20
+
21
+
22
+
23
+    @Autowired
24
+    public 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", method=RequestMethod.POST)
35
+    public ResponseEntity<?> createPoll(@Valid @RequestBody Poll poll) {
36
+        poll = pollRepository.save(poll);
37
+        URI newPollUri = ServletUriComponentsBuilder
38
+                .fromCurrentRequest()
39
+                .path("/{id}")
40
+                .buildAndExpand(poll.getId())
41
+                .toUri();
42
+        HttpHeaders httpHeaders = new HttpHeaders();
43
+        httpHeaders.setLocation(newPollUri);
44
+        return new ResponseEntity<>(httpHeaders, HttpStatus.CREATED);
45
+    }
46
+
47
+
48
+    @RequestMapping(value="/polls/{pollId}", method=RequestMethod.GET)
49
+    public ResponseEntity<?> getPoll(@PathVariable Long pollId) {
50
+        Poll p = pollRepository.findOne(pollId);
51
+        return new ResponseEntity<> (p, HttpStatus.OK);
52
+    }
53
+
54
+    @RequestMapping(value="/polls/{pollId}", method=RequestMethod.PUT)
55
+    public ResponseEntity<?> updatePoll(@Valid @RequestBody Poll poll, @PathVariable Long pollId) {
56
+        // Save the entity
57
+        Poll p = pollRepository.save(poll);
58
+        return new ResponseEntity<>(HttpStatus.OK);
59
+    }
60
+
61
+    @RequestMapping(value="/polls/{pollId}", method=RequestMethod.DELETE)
62
+    public ResponseEntity<?> deletePoll(@PathVariable Long pollId) {
63
+        pollRepository.delete(pollId);
64
+        return new ResponseEntity<>(HttpStatus.OK);
65
+    }
66
+
67
+    public void verifyPoll(Long id) {
68
+        if (pollRepository.findOne(id) == null){
69
+            throw new ResourceNotFoundException("Sorry Unavailable");
70
+        }
71
+    }
72
+
73
+}

+ 45
- 0
src/main/java/io/zipcoder/tc_spring_poll_application/controller/VoteController.java 파일 보기

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

+ 34
- 0
src/main/java/io/zipcoder/tc_spring_poll_application/domain/Option.java 파일 보기

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

+ 50
- 0
src/main/java/io/zipcoder/tc_spring_poll_application/domain/Poll.java 파일 보기

@@ -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 파일 보기

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

+ 66
- 0
src/main/java/io/zipcoder/tc_spring_poll_application/dto/error/ErrorDetail.java 파일 보기

@@ -0,0 +1,66 @@
1
+package io.zipcoder.tc_spring_poll_application.dto.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(String message) {
48
+        return developerMessage;
49
+    }
50
+
51
+    public void setDeveloperMessage(String developerMessage) {
52
+        this.developerMessage = developerMessage;
53
+    }
54
+
55
+    public String getDeveloperMessage() {
56
+        return developerMessage;
57
+    }
58
+
59
+    public Map<String, List<ValidationError>> getErrors() {
60
+        return errors;
61
+    }
62
+
63
+    public void setErrors(Map<String, List<ValidationError>> errors) {
64
+        this.errors = errors;
65
+    }
66
+}

+ 51
- 0
src/main/java/io/zipcoder/tc_spring_poll_application/dto/error/RestExceptionHandler.java 파일 보기

@@ -0,0 +1,51 @@
1
+package io.zipcoder.tc_spring_poll_application.dto.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.getDeveloperMessage(rnfe.getMessage());
29
+        errorDetail.setDetail(rnfe.getLocalizedMessage());
30
+        return new ResponseEntity<>(errorDetail, HttpStatus.NOT_FOUND);
31
+    }
32
+
33
+    @ExceptionHandler(MethodArgumentNotValidException.class)
34
+    public ResponseEntity<?> handleValidationError(  MethodArgumentNotValidException manve, HttpServletRequest request){
35
+        ErrorDetail errorDetail = new ErrorDetail();
36
+        List<FieldError> fieldErrors =  manve.getBindingResult().getFieldErrors();
37
+        for(FieldError fe : fieldErrors) {
38
+
39
+            List<ValidationError> validationErrorList = errorDetail.getErrors().get(fe.getField());
40
+            if(validationErrorList == null) {
41
+                validationErrorList = new ArrayList<>();
42
+                errorDetail.getErrors().put(fe.getField(), validationErrorList);
43
+            }
44
+            ValidationError validationError = new ValidationError();
45
+            validationError.setCode(fe.getCode());
46
+            validationError.setMessage(messageSource.getMessage(fe, null));
47
+            validationErrorList.add(validationError);
48
+        }
49
+        return new ResponseEntity<>(fieldErrors, HttpStatus.NOT_FOUND);
50
+    }
51
+}

+ 23
- 0
src/main/java/io/zipcoder/tc_spring_poll_application/dto/error/ValidationError.java 파일 보기

@@ -0,0 +1,23 @@
1
+package io.zipcoder.tc_spring_poll_application.dto.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 파일 보기

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

+ 10
- 0
src/main/java/io/zipcoder/tc_spring_poll_application/repositories/OptionRepository.java 파일 보기

@@ -0,0 +1,10 @@
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
+import org.springframework.data.repository.PagingAndSortingRepository;
6
+import org.springframework.stereotype.Repository;
7
+
8
+@Repository
9
+public interface OptionRepository extends CrudRepository<Option, Long> {
10
+}

+ 10
- 0
src/main/java/io/zipcoder/tc_spring_poll_application/repositories/PollRepository.java 파일 보기

@@ -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
+import org.springframework.stereotype.Repository;
7
+
8
+@Repository
9
+public interface PollRepository extends PagingAndSortingRepository<Poll, Long> {
10
+}

+ 18
- 0
src/main/java/io/zipcoder/tc_spring_poll_application/repositories/VoteRepository.java 파일 보기

@@ -0,0 +1,18 @@
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
+import org.springframework.data.repository.PagingAndSortingRepository;
7
+import org.springframework.stereotype.Repository;
8
+
9
+@Repository
10
+public interface VoteRepository extends CrudRepository<Vote, Long> {
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
+        Iterable<Vote> findVotesByPoll(Long pollId);
16
+
17
+        Iterable<Vote> findById(Long pollId);
18
+}

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

+ 2
- 0
src/main/resources/messages.properties 파일 보기

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