Browse Source

Poll controller Part 3.2 working

William Brown 6 years ago
parent
commit
dbba4f3443

+ 22
- 4
src/main/java/io/zipcoder/tc_spring_poll_application/controller/PollController.java View File

5
 import org.springframework.beans.factory.annotation.Autowired;
5
 import org.springframework.beans.factory.annotation.Autowired;
6
 import org.springframework.http.HttpStatus;
6
 import org.springframework.http.HttpStatus;
7
 import org.springframework.http.ResponseEntity;
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
 import org.springframework.web.servlet.support.ServletUriComponentsBuilder;
9
 import org.springframework.web.servlet.support.ServletUriComponentsBuilder;
13
 
10
 
14
 import java.net.URI;
11
 import java.net.URI;
41
 
38
 
42
         return new ResponseEntity<>(newPollUri, HttpStatus.CREATED);
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 View File

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