|
@@ -1,9 +1,11 @@
|
|
|
package es.uv.garcosda.controllers;
|
|
|
|
|
|
import java.text.SimpleDateFormat;
|
|
|
+import java.time.Duration;
|
|
|
import java.util.Date;
|
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.http.MediaType;
|
|
|
import org.springframework.web.bind.annotation.CrossOrigin;
|
|
|
import org.springframework.web.bind.annotation.DeleteMapping;
|
|
|
import org.springframework.web.bind.annotation.GetMapping;
|
|
@@ -16,6 +18,7 @@ import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
import es.uv.garcosda.domain.Document;
|
|
|
import es.uv.garcosda.services.NewsService;
|
|
|
+import reactor.core.publisher.Flux;
|
|
|
import reactor.core.publisher.Mono;
|
|
|
|
|
|
@RestController
|
|
@@ -31,6 +34,11 @@ public class NewsController {
|
|
|
return this.ns.findById(id);
|
|
|
}
|
|
|
|
|
|
+ @GetMapping(produces = MediaType.TEXT_EVENT_STREAM_VALUE)
|
|
|
+ public Flux<Document> getAll() {
|
|
|
+ return this.ns.findAll().delayElements(Duration.ofMillis(500));
|
|
|
+ }
|
|
|
+
|
|
|
@PostMapping()
|
|
|
public Mono<Document> insert(@RequestBody Document n){
|
|
|
n.setDateAdd(new SimpleDateFormat("dd-MM-yyyy").format(new Date()));
|