Chaitali Patel 5 年 前
コミット
37b114e885

+ 24
- 0
src/main/java/io/zipcoder/tc_spring_poll_application/Contoller/PollContoller.java ファイルの表示

@@ -0,0 +1,24 @@
1
+package io.zipcoder.tc_spring_poll_application.Contoller;
2
+
3
+import io.zipcoder.tc_spring_poll_application.Repository.PollRepository;
4
+import io.zipcoder.tc_spring_poll_application.domain.Poll;
5
+import org.springframework.beans.factory.annotation.Autowired;
6
+import org.springframework.data.repository.CrudRepository;
7
+import org.springframework.http.HttpStatus;
8
+import org.springframework.http.ResponseEntity;
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 PollContoller {
15
+    @Autowired
16
+    public PollContoller(PollRepository pollRepository) {
17
+    }
18
+    @RequestMapping(value="/polls", method= RequestMethod.GET)
19
+    public ResponseEntity<Iterable<Poll>> getAllPolls() {
20
+        CrudRepository pollRepository = null;
21
+        Iterable<Poll> allPolls = pollRepository.findAll();
22
+        return new ResponseEntity<>(allPolls, HttpStatus.OK);
23
+    }
24
+}

+ 7
- 0
src/main/java/io/zipcoder/tc_spring_poll_application/Repository/OptionRepository.java ファイルの表示

@@ -0,0 +1,7 @@
1
+package io.zipcoder.tc_spring_poll_application.Repository;
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/Repository/PollRepository.java ファイルの表示

@@ -0,0 +1,7 @@
1
+package io.zipcoder.tc_spring_poll_application.Repository;
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/Repository/VoteRepository.java ファイルの表示

@@ -0,0 +1,7 @@
1
+package io.zipcoder.tc_spring_poll_application.Repository;
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
+}

+ 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 org.springframework.data.annotation.Id;
4
+
5
+import javax.persistence.Column;
6
+import javax.persistence.Entity;
7
+import javax.persistence.GeneratedValue;
8
+
9
+@Entity
10
+public class Option {
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
+}

+ 44
- 0
src/main/java/io/zipcoder/tc_spring_poll_application/domain/Poll.java ファイルの表示

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

+ 31
- 0
src/main/java/io/zipcoder/tc_spring_poll_application/domain/Vote.java ファイルの表示

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