Преглед на файлове

working on put and delete services

Keith Brinker преди 8 години
родител
ревизия
6f9bea9b92
променени са 1 файла, в които са добавени 14 реда и са изтрити 4 реда
  1. 14
    4
      src/main/java/io/zipcoder/tc_spring_poll_application/controller/PollController.java

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

@@ -5,10 +5,7 @@ import io.zipcoder.tc_spring_poll_application.repositories.PollRepository;
5 5
 import org.springframework.http.HttpHeaders;
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 javax.inject.Inject;
@@ -40,4 +37,17 @@ public class PollController {
40 37
         return new ResponseEntity<>(null,responseHeaders, HttpStatus.CREATED);
41 38
     }
42 39
 
40
+    @RequestMapping(value="/polls/{pollId}", method=RequestMethod.PUT)
41
+    public ResponseEntity<?> updatePoll(@RequestBody Poll poll, @PathVariable Long pollId) {
42
+        // Save the entity
43
+        Poll p = pollRepository.save(poll);
44
+        return new ResponseEntity<>(HttpStatus.OK);
45
+    }
46
+
47
+    @RequestMapping(value="/polls/{pollId}", method=RequestMethod.DELETE)
48
+    public ResponseEntity<?> deletePoll(@PathVariable Long pollId) {
49
+        pollRepository.delete(pollId);
50
+        return new ResponseEntity<>(HttpStatus.OK);
51
+    }
52
+
43 53
 }