#29 Steffon Williams

otevřený
Stwillia94 chce sloučit 1 revizí z větve Stwillia94/SpringQuickPoll:master do větve master

+ 12
- 0
pom.xml Zobrazit soubor

@@ -7,6 +7,18 @@
7 7
     <groupId>io.zipcoder</groupId>
8 8
     <artifactId>spring-demo</artifactId>
9 9
     <version>1.0-SNAPSHOT</version>
10
+    <build>
11
+        <plugins>
12
+            <plugin>
13
+                <groupId>org.apache.maven.plugins</groupId>
14
+                <artifactId>maven-compiler-plugin</artifactId>
15
+                <configuration>
16
+                    <source>8</source>
17
+                    <target>8</target>
18
+                </configuration>
19
+            </plugin>
20
+        </plugins>
21
+    </build>
10 22
     <parent>
11 23
         <groupId>org.springframework.boot</groupId>
12 24
         <artifactId>spring-boot-starter-parent</artifactId>

+ 29
- 0
src/main/java/io/zipcoder/tc_spring_poll_application/controller/PollController.java Zobrazit soubor

@@ -0,0 +1,29 @@
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.repositories.PollRepository;
5
+import org.springframework.beans.factory.annotation.Autowired;
6
+import org.springframework.http.HttpStatus;
7
+import org.springframework.http.ResponseEntity;
8
+import org.springframework.web.bind.annotation.GetMapping;
9
+import org.springframework.web.bind.annotation.RequestMapping;
10
+import org.springframework.web.bind.annotation.RequestMethod;
11
+import org.springframework.web.bind.annotation.RestController;
12
+
13
+@RestController
14
+public class PollController {
15
+    PollRepository pollRepository;
16
+
17
+    @Autowired
18
+    public PollController(PollRepository pollRepository){
19
+        this.pollRepository = pollRepository;
20
+    }
21
+
22
+    @RequestMapping(value = "/polls", method = RequestMethod.GET)
23
+    public ResponseEntity<Iterable<Poll>> getAllPolls() {
24
+        Iterable<Poll> allPolls = pollRepository.findAll();
25
+        return new ResponseEntity<>(allPolls, HttpStatus.OK);
26
+    }
27
+
28
+
29
+}

+ 34
- 0
src/main/java/io/zipcoder/tc_spring_poll_application/domain/Option.java Zobrazit soubor

@@ -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
+    @Id
11
+    @GeneratedValue
12
+    @Column(name = "OPTION_ID")
13
+    private Long id;
14
+
15
+    @Column(name = "OPTION_VALUE")
16
+   private String value;
17
+
18
+    public Long getId(){
19
+        return id;
20
+    }
21
+
22
+    public void setId(){
23
+        this.id = id;
24
+    }
25
+
26
+    public String get(){
27
+        return value;
28
+    }
29
+
30
+    public void setValue(){
31
+        this.value = value;
32
+    }
33
+
34
+}

+ 45
- 0
src/main/java/io/zipcoder/tc_spring_poll_application/domain/Poll.java Zobrazit soubor

@@ -0,0 +1,45 @@
1
+package io.zipcoder.tc_spring_poll_application.domain;
2
+
3
+import javax.persistence.*;
4
+import java.util.Set;
5
+
6
+@Entity
7
+public class Poll {
8
+
9
+    @Id
10
+    @GeneratedValue
11
+    @Column(name = "POLL_ID")
12
+    private Long id;
13
+
14
+    @Column(name = "QUESTION")
15
+    String question;
16
+
17
+    @OneToMany(cascade = CascadeType.ALL)
18
+    @JoinColumn(name = "POLL_ID")
19
+    @OrderBy
20
+    Set<Option> options;
21
+
22
+    public Long getId() {
23
+        return id;
24
+    }
25
+
26
+    public void setId(Long id) {
27
+        this.id = id;
28
+    }
29
+
30
+    public String getQuestion() {
31
+        return question;
32
+    }
33
+
34
+    public void setQuestion(String question) {
35
+        this.question = question;
36
+    }
37
+
38
+    public Set<Option> getOptions() {
39
+        return options;
40
+    }
41
+
42
+    public void setOptions(Set<Option> options) {
43
+        this.options = options;
44
+    }
45
+}

+ 31
- 0
src/main/java/io/zipcoder/tc_spring_poll_application/domain/Vote.java Zobrazit soubor

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

+ 7
- 0
src/main/java/io/zipcoder/tc_spring_poll_application/repositories/OptionRepository.java Zobrazit soubor

@@ -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 Zobrazit soubor

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

+ 7
- 0
src/main/java/io/zipcoder/tc_spring_poll_application/repositories/VoteRepository.java Zobrazit soubor

@@ -0,0 +1,7 @@
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.repository.CrudRepository;
5
+
6
+public interface VoteRepository extends CrudRepository<Vote, Long> {
7
+}

+ 8
- 0
src/test/java/io/zipcoder/tc_spring_poll_application/QuickPollApplicationTest.java Zobrazit soubor

@@ -1,4 +1,12 @@
1 1
 package io.zipcoder.tc_spring_poll_application;
2 2
 
3
+import javax.persistence.Column;
4
+import javax.persistence.Entity;
5
+import javax.persistence.GeneratedValue;
6
+import javax.persistence.Id;
7
+
8
+
3 9
 public class QuickPollApplicationTest {
10
+
11
+
4 12
 }