|
@@ -1,5 +1,8 @@
|
|
|
package es.uv.garcosda.controllers;
|
|
|
|
|
|
+import static org.springframework.hateoas.server.mvc.WebMvcLinkBuilder.linkTo;
|
|
|
+import static org.springframework.hateoas.server.mvc.WebMvcLinkBuilder.methodOn;
|
|
|
+
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
import java.util.Optional;
|
|
@@ -18,6 +21,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
import org.springframework.web.bind.annotation.RequestParam;
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
+
|
|
|
import es.uv.garcosda.domain.Video;
|
|
|
import es.uv.garcosda.services.VideoService;
|
|
|
|
|
@@ -48,6 +52,10 @@ public class VideoController {
|
|
|
videos = vs.findByUserId(userId.get());
|
|
|
}
|
|
|
|
|
|
+ for (Video v : videos) {
|
|
|
+ v.add(linkTo(methodOn(VideoController.class).findVideoById(v.getId().toString())).withSelfRel());
|
|
|
+ }
|
|
|
+
|
|
|
return new ResponseEntity<List<Video>>(videos, HttpStatus.OK);
|
|
|
}
|
|
|
|
|
@@ -60,6 +68,8 @@ public class VideoController {
|
|
|
return new ResponseEntity<Video>(new Video(), HttpStatus.OK);
|
|
|
}
|
|
|
else {
|
|
|
+ Video v = video.get();
|
|
|
+ v.add(linkTo(methodOn(VideoController.class).findVideoById(id)).withSelfRel());
|
|
|
return new ResponseEntity<Video>(video.get(), HttpStatus.NOT_FOUND);
|
|
|
}
|
|
|
}
|
|
@@ -68,7 +78,9 @@ public class VideoController {
|
|
|
public ResponseEntity<Video> createVideo(@RequestBody Video video) {
|
|
|
LOGGER.debug("Create video");
|
|
|
Video createdVideo = vs.create(video);
|
|
|
+
|
|
|
if(createdVideo.getId() != null) {
|
|
|
+ createdVideo.add(linkTo(methodOn(VideoController.class).findVideoById(createdVideo.getId().toString())).withSelfRel());
|
|
|
return new ResponseEntity<Video>(createdVideo, HttpStatus.OK);
|
|
|
}
|
|
|
else {
|