diff --git a/pom.xml b/pom.xml
index ed84c9b..55f5e1b 100644
--- a/pom.xml
+++ b/pom.xml
@@ -7,6 +7,18 @@
io.zipcoder
spring-demo
1.0-SNAPSHOT
+
+
+
+ org.apache.maven.plugins
+ maven-compiler-plugin
+
+ 8
+ 8
+
+
+
+
org.springframework.boot
spring-boot-starter-parent
diff --git a/src/main/java/io/zipcoder/tc_spring_poll_application/controller/ComputeResultController.java b/src/main/java/io/zipcoder/tc_spring_poll_application/controller/ComputeResultController.java
new file mode 100644
index 0000000..77a9dd5
--- /dev/null
+++ b/src/main/java/io/zipcoder/tc_spring_poll_application/controller/ComputeResultController.java
@@ -0,0 +1,45 @@
+package io.zipcoder.tc_spring_poll_application.controller;
+
+import io.zipcoder.tc_spring_poll_application.domain.Option;
+import io.zipcoder.tc_spring_poll_application.domain.Poll;
+import io.zipcoder.tc_spring_poll_application.domain.Vote;
+import io.zipcoder.tc_spring_poll_application.dtos.OptionCount;
+import io.zipcoder.tc_spring_poll_application.dtos.VoteResult;
+import io.zipcoder.tc_spring_poll_application.repositories.PollRepository;
+import io.zipcoder.tc_spring_poll_application.repositories.VoteRepository;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.http.HttpStatus;
+import org.springframework.http.ResponseEntity;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.bind.annotation.RestController;
+
+import java.util.ArrayList;
+
+@RestController
+public class ComputeResultController {
+ private VoteRepository voteRepository;
+ private PollRepository pollRepository;
+
+ @Autowired
+ public ComputeResultController(VoteRepository voteRepository, PollRepository pollRepository){
+ this.voteRepository = voteRepository;
+ this.pollRepository = pollRepository;
+ }
+
+ @GetMapping(value = "/computeresult")
+ public ResponseEntity> computeResult(@RequestParam Long pollId) {
+ VoteResult voteResult = new VoteResult();
+ Iterable allVotes = voteRepository.findVotesByPoll(pollId);
+
+ Poll poll = pollRepository.findOne(pollId);
+ voteResult.setResults(new ArrayList());
+ for (Option o : poll.getOptions()) {
+ OptionCount optionCount = new OptionCount();
+ optionCount.setOptionId(o.getId());
+ optionCount.setCount(Math.toIntExact(((ArrayList) allVotes).stream().filter(v -> v.getOption().equals(o)).count()));
+ voteResult.getResults().add(optionCount);
+ }
+ return new ResponseEntity(voteResult, HttpStatus.OK);
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/io/zipcoder/tc_spring_poll_application/controller/PollController.java b/src/main/java/io/zipcoder/tc_spring_poll_application/controller/PollController.java
new file mode 100644
index 0000000..fe64eab
--- /dev/null
+++ b/src/main/java/io/zipcoder/tc_spring_poll_application/controller/PollController.java
@@ -0,0 +1,71 @@
+package io.zipcoder.tc_spring_poll_application.controller;
+
+import io.zipcoder.tc_spring_poll_application.domain.Poll;
+import io.zipcoder.tc_spring_poll_application.exception.ResourceNotFoundException;
+import io.zipcoder.tc_spring_poll_application.repositories.PollRepository;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.data.domain.Pageable;
+import org.springframework.data.domain.Page;
+import org.springframework.http.HttpHeaders;
+import org.springframework.http.HttpStatus;
+import org.springframework.http.ResponseEntity;
+import org.springframework.web.bind.annotation.*;
+import org.springframework.web.servlet.support.ServletUriComponentsBuilder;
+
+import javax.validation.Valid;
+import java.net.URI;
+
+@RestController
+public class PollController {
+ public PollRepository pollRepository;
+
+ @Autowired
+ public PollController(PollRepository pollRepository){
+ this.pollRepository = pollRepository;
+ }
+
+ @GetMapping(value="/polls")
+ public ResponseEntity> getAllPolls(Pageable P) {
+ Page allPolls = pollRepository.findAll(P);
+ return new ResponseEntity<>(allPolls, HttpStatus.OK);
+ }
+
+ @PostMapping(value="/polls")
+ public ResponseEntity> createPoll(@RequestBody @Valid Poll poll) {
+ poll = pollRepository.save(poll);
+ URI newPollUri = ServletUriComponentsBuilder
+ .fromCurrentRequest()
+ .path("/{id}")
+ .buildAndExpand(poll.getId())
+ .toUri();
+ HttpHeaders hh = new HttpHeaders();
+ hh.setLocation(newPollUri);
+ return new ResponseEntity<>(hh, HttpStatus.CREATED);
+ }
+
+ @GetMapping(value="/polls/{pollId}")
+ public ResponseEntity> getPoll(@PathVariable Long pollId) {
+ Poll p = pollRepository.findOne(pollId);
+ return new ResponseEntity<> (p, HttpStatus.OK);
+ }
+
+ @PutMapping(value="/polls/{pollId}")
+ public ResponseEntity> updatePoll(@RequestBody @Valid Poll poll, @PathVariable Long pollId) {
+ // Save the entity
+ Poll p = pollRepository.save(poll);
+ return new ResponseEntity<>(HttpStatus.OK);
+ }
+
+ @DeleteMapping(value="/polls/{pollId}")
+ public ResponseEntity> deletePoll(@PathVariable Long pollId) {
+ pollRepository.delete(pollId);
+ return new ResponseEntity<>(HttpStatus.OK);
+ }
+
+ public void verifyPoll(Long pollId){
+ if(!pollRepository.exists(pollId)){
+ throw new ResourceNotFoundException();
+ }
+ }
+
+}
diff --git a/src/main/java/io/zipcoder/tc_spring_poll_application/controller/VoteController.java b/src/main/java/io/zipcoder/tc_spring_poll_application/controller/VoteController.java
new file mode 100644
index 0000000..d3603a8
--- /dev/null
+++ b/src/main/java/io/zipcoder/tc_spring_poll_application/controller/VoteController.java
@@ -0,0 +1,42 @@
+package io.zipcoder.tc_spring_poll_application.controller;
+
+import io.zipcoder.tc_spring_poll_application.domain.Vote;
+import io.zipcoder.tc_spring_poll_application.repositories.VoteRepository;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.http.HttpHeaders;
+import org.springframework.http.HttpStatus;
+import org.springframework.http.ResponseEntity;
+import org.springframework.web.bind.annotation.*;
+import org.springframework.web.servlet.support.ServletUriComponentsBuilder;
+
+@RestController
+public class VoteController {
+ private VoteRepository voteRepository;
+
+ @Autowired
+ public VoteController(VoteRepository voteRepository) {
+ this.voteRepository = voteRepository;
+ }
+
+ @PostMapping("/polls/{pollId}/votes")
+ public ResponseEntity> createVote(@PathVariable Long pollId, @RequestBody Vote
+ vote) {
+ vote = voteRepository.save(vote);
+ // Set the headers for the newly created resource
+ HttpHeaders responseHeaders = new HttpHeaders();
+ responseHeaders.setLocation(ServletUriComponentsBuilder.
+ fromCurrentRequest().path("/{id}").buildAndExpand(vote.getId()).toUri());
+ return new ResponseEntity<>(null, responseHeaders, HttpStatus.CREATED);
+ }
+
+ @GetMapping(value="/polls/votes")
+ public Iterable getAllVotes() {
+ return voteRepository.findAll();
+ }
+
+ @GetMapping(value="/polls/{pollId}/votes")
+ public Iterable getVote(@PathVariable Long pollId) {
+ return voteRepository.findVotesByPoll(pollId);
+ }
+}
+
diff --git a/src/main/java/io/zipcoder/tc_spring_poll_application/domain/Option.java b/src/main/java/io/zipcoder/tc_spring_poll_application/domain/Option.java
new file mode 100644
index 0000000..55556b2
--- /dev/null
+++ b/src/main/java/io/zipcoder/tc_spring_poll_application/domain/Option.java
@@ -0,0 +1,33 @@
+package io.zipcoder.tc_spring_poll_application.domain;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+
+@Entity
+public class Option {
+ @Id
+ @GeneratedValue
+ @Column(name = "OPTION_ID")
+ public Long id;
+
+ @Column(name = "OPTION_VALUE")
+ public String value;
+
+ public Long getId() {
+ return id;
+ }
+
+ public void setId(Long id) {
+ this.id = id;
+ }
+
+ public String getValue() {
+ return value;
+ }
+
+ public void setValue(String value) {
+ this.value = value;
+ }
+}
diff --git a/src/main/java/io/zipcoder/tc_spring_poll_application/domain/Poll.java b/src/main/java/io/zipcoder/tc_spring_poll_application/domain/Poll.java
new file mode 100644
index 0000000..3c768c6
--- /dev/null
+++ b/src/main/java/io/zipcoder/tc_spring_poll_application/domain/Poll.java
@@ -0,0 +1,50 @@
+package io.zipcoder.tc_spring_poll_application.domain;
+
+import org.hibernate.validator.constraints.NotEmpty;
+
+import javax.persistence.*;
+import javax.validation.constraints.Size;
+import java.util.Set;
+
+@Entity
+public class Poll {
+ @Id
+ @GeneratedValue
+ @Column(name = "POLL_ID")
+ public Long id;
+
+ @Column(name = "QUESTION")
+ @NotEmpty
+ public String question;
+
+
+ @OneToMany(cascade = CascadeType.ALL)
+ @JoinColumn(name = "POLL_ID")
+ @OrderBy
+ @Size(min=2, max = 6)
+ Set