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 getOne(@PathVariable("id") Integer id) { return this.ns.findById(id); } @PostMapping() public Mono insert(@RequestBody Document n){ n.setDateAdd(new SimpleDateFormat("dd-MM-yyyy").format(new Date())); return this.ns.insert(n); } @PutMapping() public Mono update(@RequestBody Document n){ return this.ns.update(n); } @DeleteMapping("{id}") public Mono delete(@PathVariable("id") Integer id){ return this.ns.deleteById(id).then(Mono.just(id)); } }