CWinarski преди 8 години
родител
ревизия
c05929044d

+ 1
- 1
pom.xml Целия файл

@@ -15,7 +15,7 @@
15 15
     </parent>
16 16
     <properties>
17 17
         <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
18
-        <start-class>io.zipcoder.tc_spring_poll_application.QuickPollApplication</start-class>
18
+        <start-class>io.zipcoder.springdemo.QuickPollApplication</start-class>
19 19
         <java.version>1.7</java.version>
20 20
     </properties>
21 21
     <dependencies>

+ 11
- 0
src/main/java/io/zipcoder/tc_spring_poll_application/controller/PollController.java Целия файл

@@ -1,6 +1,11 @@
1 1
 package io.zipcoder.tc_spring_poll_application.controller;
2 2
 
3
+import io.zipcoder.tc_spring_poll_application.domain.Poll;
3 4
 import io.zipcoder.tc_spring_poll_application.repositories.PollRepository;
5
+import org.springframework.http.HttpStatus;
6
+import org.springframework.http.ResponseEntity;
7
+import org.springframework.web.bind.annotation.RequestMapping;
8
+import org.springframework.web.bind.annotation.RequestMethod;
4 9
 import org.springframework.web.bind.annotation.RestController;
5 10
 
6 11
 import javax.inject.Inject;
@@ -11,4 +16,10 @@ public class PollController {
11 16
     @Inject
12 17
     private PollRepository pollRepository;
13 18
 
19
+    @RequestMapping(value="/polls", method= RequestMethod.GET)
20
+    public ResponseEntity<Iterable<Poll>> getAllPolls() {
21
+        Iterable<Poll> allPolls = pollRepository.findAll();
22
+        return new ResponseEntity<>(allPolls, HttpStatus.OK);
23
+    }
24
+
14 25
 }

+ 3
- 3
src/main/java/io/zipcoder/tc_spring_poll_application/domain/Option.java Целия файл

@@ -11,16 +11,16 @@ public class Option {
11 11
     @Id // specifies primary key of entity
12 12
     @GeneratedValue // configures the way of increment of the specified column (field)
13 13
     @Column(name = "OPTION_ID")// specifies mapped column for a persisitence property. Without this annotation the framework assumes the field's variable-name is the persistent property
14
-    private long id;
14
+    private Long id;
15 15
 
16 16
     @Column(name = "OPTION_VALUE")// specifies mapped column for persistence value
17 17
     private String value;
18 18
 
19
-    public long getId() {
19
+    public Long getId() {
20 20
         return id;
21 21
     }
22 22
 
23
-    public void setId(long id) {
23
+    public void setId(Long id) {
24 24
         this.id = id;
25 25
     }
26 26
 

+ 4
- 4
src/main/java/io/zipcoder/tc_spring_poll_application/domain/Poll.java Целия файл

@@ -8,8 +8,8 @@ public class Poll {
8 8
 
9 9
     @Id
10 10
     @GeneratedValue
11
-    @Column(name = "Poll_ID")
12
-    private long id;
11
+    @Column(name = "POLL_ID")
12
+    private Long id;
13 13
 
14 14
     @Column(name = "QUESTION")
15 15
     private String question;
@@ -19,11 +19,11 @@ public class Poll {
19 19
     @OrderBy
20 20
     private Set<Option> options;
21 21
 
22
-    public long getId() {
22
+    public Long getId() {
23 23
         return id;
24 24
     }
25 25
 
26
-    public void setId(long id) {
26
+    public void setId(Long id) {
27 27
         this.id = id;
28 28
     }
29 29
 

+ 24
- 1
src/main/java/io/zipcoder/tc_spring_poll_application/domain/Vote.java Целия файл

@@ -1,8 +1,31 @@
1 1
 package io.zipcoder.tc_spring_poll_application.domain;
2 2
 
3
-import javax.persistence.Entity;
3
+import javax.persistence.*;
4 4
 
5 5
 @Entity
6 6
 public class Vote {
7
+    @Id
8
+    @GeneratedValue
9
+    @Column(name = "VOTE_ID")
10
+    private Long id;
7 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
+    }
8 31
 }

+ 4
- 2
src/main/java/io/zipcoder/tc_spring_poll_application/repositories/OptionRepository.java Целия файл

@@ -1,7 +1,9 @@
1 1
 package io.zipcoder.tc_spring_poll_application.repositories;
2 2
 
3
-import io.zipcoder.tc_spring_poll_application.domain.Vote;
3
+import io.zipcoder.tc_spring_poll_application.domain.Option;
4 4
 import org.springframework.data.repository.CrudRepository;
5 5
 
6
-public interface OptionRepository extends CrudRepository<Vote, Long>{
6
+public interface OptionRepository extends CrudRepository<Option, Long>{
7
+    //these are DAOs pr Data Access Objects they provide abstraction for interacting with data stores
8
+    // ypu have usually one repository per domain object
7 9
 }

+ 4
- 2
src/main/java/io/zipcoder/tc_spring_poll_application/repositories/PollRepository.java Целия файл

@@ -1,7 +1,9 @@
1 1
 package io.zipcoder.tc_spring_poll_application.repositories;
2 2
 
3
-import io.zipcoder.tc_spring_poll_application.domain.Vote;
3
+import io.zipcoder.tc_spring_poll_application.domain.Poll;
4 4
 import org.springframework.data.repository.CrudRepository;
5 5
 
6
-public interface PollRepository extends CrudRepository<Vote, Long>{
6
+public interface PollRepository extends CrudRepository<Poll, Long>{
7
+    //these are DAOs pr Data Access Objects they provide abstraction for interacting with data stores
8
+    // ypu have usually one repository per domain object
7 9
 }

+ 2
- 0
src/main/java/io/zipcoder/tc_spring_poll_application/repositories/VoteRepository.java Целия файл

@@ -4,4 +4,6 @@ import io.zipcoder.tc_spring_poll_application.domain.Vote;
4 4
 import org.springframework.data.repository.CrudRepository;
5 5
 
6 6
 public interface VoteRepository extends CrudRepository<Vote, Long> {
7
+    //these are DAOs pr Data Access Objects they provide abstraction for interacting with data stores
8
+    // ypu have usually one repository per domain object
7 9
 }