Lauren Green 7 лет назад
Родитель
Сommit
350b6ddc2d

+ 9
- 0
pom.xml Просмотреть файл

@@ -13,6 +13,15 @@
13 13
         <version>1.5.3.RELEASE</version>
14 14
         <relativePath/> <!-- lookup parent from repository -->
15 15
     </parent>
16
+    <build>
17
+        <plugins>
18
+            <!-- Spring Boot Maven -->
19
+            <plugin>
20
+                <groupId>org.springframework.boot</groupId>
21
+                <artifactId>spring-boot-maven-plugin</artifactId>
22
+            </plugin>
23
+        </plugins>
24
+    </build>
16 25
     <properties>
17 26
         <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
18 27
         <start-class>io.zipcoder.tc_spring_poll_application.QuickPollApplication</start-class>

+ 27
- 0
src/main/java/io/zipcoder/tc_spring_poll_application/controller/PollController.java Просмотреть файл

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