|
@@ -1,7 +1,6 @@
|
|
package es.uv.garcosda.controllers;
|
|
package es.uv.garcosda.controllers;
|
|
|
|
|
|
import java.util.List;
|
|
import java.util.List;
|
|
-import java.util.Optional;
|
|
|
|
|
|
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.LoggerFactory;
|
|
import org.slf4j.LoggerFactory;
|
|
@@ -12,11 +11,13 @@ import org.springframework.web.bind.annotation.DeleteMapping;
|
|
import org.springframework.web.bind.annotation.GetMapping;
|
|
import org.springframework.web.bind.annotation.GetMapping;
|
|
import org.springframework.web.bind.annotation.PathVariable;
|
|
import org.springframework.web.bind.annotation.PathVariable;
|
|
import org.springframework.web.bind.annotation.PostMapping;
|
|
import org.springframework.web.bind.annotation.PostMapping;
|
|
|
|
+import org.springframework.web.bind.annotation.PutMapping;
|
|
import org.springframework.web.bind.annotation.RequestBody;
|
|
import org.springframework.web.bind.annotation.RequestBody;
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
import es.uv.garcosda.domain.Post;
|
|
import es.uv.garcosda.domain.Post;
|
|
|
|
+import es.uv.garcosda.domain.PostDTO;
|
|
import es.uv.garcosda.services.PostService;
|
|
import es.uv.garcosda.services.PostService;
|
|
|
|
|
|
|
|
|
|
@@ -44,6 +45,46 @@ public class BlogController {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
|
|
|
|
+ @PostMapping("posts")
|
|
|
|
+ public ResponseEntity<Post> create(@RequestBody PostDTO dto){
|
|
|
|
+ Post p = ps.add(dto);
|
|
|
|
+ if(p.getId() != null) {
|
|
|
|
+ return new ResponseEntity<Post>(p, HttpStatus.OK);
|
|
|
|
+ }
|
|
|
|
+ else {
|
|
|
|
+ return new ResponseEntity<Post>(new Post(), HttpStatus.NOT_FOUND);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @DeleteMapping("posts")
|
|
|
|
+ public ResponseEntity<String> delete(@RequestBody Post p){
|
|
|
|
+ if(ps.delete(p)) {
|
|
|
|
+ return new ResponseEntity<String>("", HttpStatus.OK);
|
|
|
|
+ }
|
|
|
|
+ else {
|
|
|
|
+ return new ResponseEntity<String>("", HttpStatus.NOT_FOUND);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @DeleteMapping("posts/{id}")
|
|
|
|
+ public ResponseEntity<String> deleteById(@PathVariable String id){
|
|
|
|
+ if(ps.deleteById(id)) {
|
|
|
|
+ return new ResponseEntity<String>("", HttpStatus.OK);
|
|
|
|
+ }
|
|
|
|
+ else {
|
|
|
|
+ return new ResponseEntity<String>("", HttpStatus.NOT_FOUND);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @PutMapping("posts")
|
|
|
|
+ public ResponseEntity<Post> update(@RequestBody Post dto){
|
|
|
|
+ Post p = ps.update(dto);
|
|
|
|
+ if(p.getId() != null) {
|
|
|
|
+ return new ResponseEntity<Post>(p, HttpStatus.OK);
|
|
|
|
+ }
|
|
|
|
+ else {
|
|
|
|
+ return new ResponseEntity<Post>(new Post(), HttpStatus.NOT_FOUND);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
|
|
}
|
|
}
|