123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051 |
- package es.uv.garcosda.controllers;
- import java.text.SimpleDateFormat;
- import java.util.Date;
- 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;
- import es.uv.garcosda.domain.Document;
- import es.uv.garcosda.services.NewsService;
- import reactor.core.publisher.Mono;
- @RestController
- @RequestMapping("/api/v1/news")
- @CrossOrigin
- public class NewsController {
-
- @Autowired
- private NewsService ns;
-
- @GetMapping("{id}")
- public Mono<Document> getOne(@PathVariable("id") Integer id) {
- return this.ns.findById(id);
- }
-
- @PostMapping()
- public Mono<Document> insert(@RequestBody Document n){
- n.setDateAdd(new SimpleDateFormat("dd-MM-yyyy").format(new Date()));
- return this.ns.insert(n);
- }
-
- @PutMapping()
- public Mono<Document> update(@RequestBody Document n){
- return this.ns.update(n);
- }
-
- @DeleteMapping("{id}")
- public Mono<Integer> delete(@PathVariable("id") Integer id){
- return this.ns.deleteById(id).then(Mono.just(id));
-
- }
-
- }
|