소스 검색

Poll controller Part 3.2 working

William Brown 5 년 전
부모
커밋
dbba4f3443

+ 22
- 4
src/main/java/io/zipcoder/tc_spring_poll_application/controller/PollController.java 파일 보기

@@ -5,10 +5,7 @@ import io.zipcoder.tc_spring_poll_application.repository.PollRepository;
5 5
 import org.springframework.beans.factory.annotation.Autowired;
6 6
 import org.springframework.http.HttpStatus;
7 7
 import org.springframework.http.ResponseEntity;
8
-import org.springframework.web.bind.annotation.RequestBody;
9
-import org.springframework.web.bind.annotation.RequestMapping;
10
-import org.springframework.web.bind.annotation.RequestMethod;
11
-import org.springframework.web.bind.annotation.RestController;
8
+import org.springframework.web.bind.annotation.*;
12 9
 import org.springframework.web.servlet.support.ServletUriComponentsBuilder;
13 10
 
14 11
 import java.net.URI;
@@ -41,4 +38,25 @@ public class PollController {
41 38
 
42 39
         return new ResponseEntity<>(newPollUri, HttpStatus.CREATED);
43 40
     }
41
+
42
+    @RequestMapping(value="/polls/{pollId}", method=RequestMethod.GET)
43
+    public ResponseEntity<?> getPoll(@PathVariable Long pollId) {
44
+        Poll p = pollRepository.findOne(pollId);
45
+        return new ResponseEntity<> (p, HttpStatus.OK);
46
+    }
47
+
48
+    @RequestMapping(value="/polls/{pollId}", method=RequestMethod.PUT)
49
+    public ResponseEntity<?> updatePoll(@RequestBody Poll poll, @PathVariable Long pollId) {
50
+        // Save the entity
51
+        Poll p = pollRepository.save(poll);
52
+        return new ResponseEntity<>(HttpStatus.OK);
53
+    }
54
+
55
+    @RequestMapping(value="/polls/{pollId}", method=RequestMethod.DELETE)
56
+    public ResponseEntity<?> deletePoll(@PathVariable Long pollId) {
57
+        pollRepository.delete(pollId);
58
+        return new ResponseEntity<>(HttpStatus.OK);
59
+    }
60
+
61
+
44 62
 }

+ 4
- 0
src/main/java/io/zipcoder/tc_spring_poll_application/controller/VoteController.java 파일 보기

@@ -0,0 +1,4 @@
1
+package io.zipcoder.tc_spring_poll_application.controller;
2
+
3
+public class VoteController {
4
+}