Soujanya Buragapu 6 vuotta sitten
vanhempi
commit
cacfd737e7

+ 4
- 2
src/main/java/io/zipcoder/tc_spring_poll_application/QuickPollApplication.java Näytä tiedosto

@@ -4,8 +4,10 @@ import org.springframework.boot.SpringApplication;
4 4
 import org.springframework.boot.autoconfigure.SpringBootApplication;
5 5
 
6 6
 @SpringBootApplication
7
-public class QuickPollApplication {
8
-    public static void main(String[] args) {
7
+public class QuickPollApplication
8
+{
9
+    public static void main(String[] args)
10
+    {
9 11
         SpringApplication.run(QuickPollApplication.class, args);
10 12
     }
11 13
 }

+ 28
- 0
src/main/java/io/zipcoder/tc_spring_poll_application/controller/PollController.java Näytä tiedosto

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

+ 37
- 0
src/main/java/io/zipcoder/tc_spring_poll_application/domain/Option.java Näytä tiedosto

@@ -0,0 +1,37 @@
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 Option() {
20
+    }
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 getValue() {
31
+        return value;
32
+    }
33
+
34
+    public void setValue(String value) {
35
+        this.value = value;
36
+    }
37
+}

+ 48
- 0
src/main/java/io/zipcoder/tc_spring_poll_application/domain/Poll.java Näytä tiedosto

@@ -0,0 +1,48 @@
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 = "QUESTION")
12
+    private Long id;
13
+
14
+    @Column(name = "POLL_ID")
15
+    private String question;
16
+
17
+    @OneToMany(cascade = CascadeType.ALL)
18
+    @JoinColumn(name = "POLL_ID")
19
+    @OrderBy
20
+    private Set<Option> options;
21
+
22
+    public Long getId() {
23
+        return id;
24
+    }
25
+
26
+    public Poll() {
27
+    }
28
+
29
+    public void setId(Long id) {
30
+        this.id = id;
31
+    }
32
+
33
+    public String getQuestion() {
34
+        return question;
35
+    }
36
+
37
+    public void setQuestion(String question) {
38
+        this.question = question;
39
+    }
40
+
41
+    public Set getOptions() {
42
+        return options;
43
+    }
44
+
45
+    public void setOptions(Set options) {
46
+        this.options = options;
47
+    }
48
+}

+ 36
- 0
src/main/java/io/zipcoder/tc_spring_poll_application/domain/Vote.java Näytä tiedosto

@@ -0,0 +1,36 @@
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
+
18
+    public Vote() {
19
+    }
20
+
21
+    public Long getId() {
22
+        return id;
23
+    }
24
+
25
+    public void setId(Long id) {
26
+        this.id = id;
27
+    }
28
+
29
+    public Option getOption() {
30
+        return option;
31
+    }
32
+
33
+    public void setOption(Option option) {
34
+        this.option = option;
35
+    }
36
+}

+ 8
- 0
src/main/java/io/zipcoder/tc_spring_poll_application/repositories/OptionRepository.java Näytä tiedosto

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

+ 7
- 0
src/main/java/io/zipcoder/tc_spring_poll_application/repositories/PollRepository.java Näytä tiedosto

@@ -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 Näytä tiedosto

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

+ 3
- 1
src/test/java/io/zipcoder/tc_spring_poll_application/QuickPollApplicationTest.java Näytä tiedosto

@@ -1,4 +1,6 @@
1 1
 package io.zipcoder.tc_spring_poll_application;
2 2
 
3
-public class QuickPollApplicationTest {
3
+public class QuickPollApplicationTest
4
+{
5
+
4 6
 }