浏览代码

CRUD Operations

dagarcos 2 年之前
父节点
当前提交
d7a35fa1b5

+ 19 - 0
src/main/java/es/uv/garcosda/controllers/NewsController.java

@@ -2,8 +2,12 @@ package es.uv.garcosda.controllers;
 
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.CrossOrigin;
+import org.springframework.web.bind.annotation.DeleteMapping;
 import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.PathVariable;
+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.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
 
@@ -24,4 +28,19 @@ public class NewsController {
         return this.ns.findById(id);
     }
 	
+	@PostMapping()
+	public Mono<Document> insert(@RequestBody Document n){
+		return this.ns.insert(n);	
+	}
+	
+	@PutMapping()
+	public Mono<Document> update(@RequestBody Document n){
+		return this.ns.update(n);
+	}
+	
+	@DeleteMapping("{id}")
+	public Mono<Void> delete(@PathVariable("id") Integer id){
+		return this.ns.deleteById(id);
+	}
+	
 }

+ 8 - 0
src/main/java/es/uv/garcosda/services/NewsService.java

@@ -26,7 +26,15 @@ public class NewsService {
 		return this.nr.save(n);
 	}
 	
+	public Mono<Document> insert(Document n) {
+		return this.nr.save(n);
+	}
+	
 	public Flux<Document> createAll(List<Document> ns){
 		return this.nr.saveAll(ns);
 	}
+	
+	public Mono<Void> deleteById(Integer id) {
+		return this.nr.deleteById(id);
+	}
 }