Нет описания

MovieController.java 4.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. package fr.natan.akkastreamfileprocessingapi.controller;
  2. import fr.natan.akkastreamfileprocessingapi.futurecompleteness.CompletableFutureResult;
  3. import fr.natan.akkastreamfileprocessingapi.models.Models;
  4. import fr.natan.akkastreamfileprocessingapi.service.AkkaStreamFileProcessing;
  5. import org.springframework.http.HttpStatus;
  6. import org.springframework.http.ResponseEntity;
  7. import org.springframework.web.bind.annotation.PathVariable;
  8. import org.springframework.web.bind.annotation.RequestMapping;
  9. import org.springframework.web.bind.annotation.RequestMethod;
  10. import org.springframework.web.bind.annotation.RestController;
  11. import play.api.libs.json.JsValue;
  12. import play.api.libs.json.Json;
  13. import scala.collection.IndexedSeq;
  14. import scala.collection.immutable.List;
  15. import scala.concurrent.Future;
  16. import java.util.concurrent.CompletableFuture;
  17. import java.util.concurrent.ExecutionException;
  18. @SuppressWarnings("SpellCheckingInspection")
  19. @RestController
  20. public class MovieController {
  21. private final AkkaStreamFileProcessing akkaStreamFilesProcessing;
  22. private final CompletableFutureResult completableFutureResult;
  23. public MovieController(AkkaStreamFileProcessing akkaStreamFilesProcessing) {
  24. this.akkaStreamFilesProcessing = akkaStreamFilesProcessing;
  25. completableFutureResult = new CompletableFutureResult();
  26. }
  27. @RequestMapping(value = "/persons/id/{personID}", method = RequestMethod.GET)
  28. private ResponseEntity<String> getPersonByID(@PathVariable(name = "personID") String personID) throws ExecutionException, InterruptedException {
  29. Future<Models.Person> personFuture = akkaStreamFilesProcessing.getPersonById(personID);
  30. CompletableFuture<Models.Person> personCompletableFuture = this.completableFutureResult.buildcompletableFuture(personFuture);
  31. Models.Person person = personCompletableFuture.get();
  32. JsValue personJs = Json.toJson(person, person.personFormat());
  33. return new ResponseEntity<>(personJs.toString(), HttpStatus.OK);
  34. }
  35. @RequestMapping(value = "/persons/name/{primaryName}", method = RequestMethod.GET)
  36. private ResponseEntity<String> getPersonByName(@PathVariable(name = "primaryName") String primaryName)
  37. throws ExecutionException, InterruptedException {
  38. Future<Models.Person> personFuture = akkaStreamFilesProcessing.getPersonByName(primaryName);
  39. CompletableFuture completableFutureResult = this.completableFutureResult.buildcompletableFuture(personFuture);
  40. Models.Person person = (Models.Person) completableFutureResult.get();
  41. JsValue personJs = Json.toJson(person, person.personFormat());
  42. return new ResponseEntity<>(personJs.toString(), HttpStatus.OK);
  43. }
  44. @RequestMapping(value = "/tvseries/id/{tvSerieId}", method = RequestMethod.GET)
  45. private ResponseEntity<String> getTvSerieByID(@PathVariable(name = "tvSerieId") String tvSerieID) throws ExecutionException, InterruptedException {
  46. Future<Models.TvSerie> tvSerieFuture = akkaStreamFilesProcessing.getTvSerieById(tvSerieID);
  47. CompletableFuture<Models.TvSerie> tvSerieCompletableFuture = this.completableFutureResult.buildcompletableFuture(tvSerieFuture);
  48. Models.TvSerie tvSerie = tvSerieCompletableFuture.get();
  49. JsValue tvSerieJs = Json.toJson(tvSerie, tvSerie.tvSerieFormat());
  50. return new ResponseEntity<>(tvSerieJs.toString(), HttpStatus.OK);
  51. }
  52. @RequestMapping(value = "/tvseries/title/{tvseriePrimaryTitle}", method = RequestMethod.GET)
  53. private ResponseEntity<List<Models.TvSerie>> getTvserieByPrimaryTitle(@PathVariable(name = "tvseriePrimaryTitle") String tvseriePrimaryTitle) {
  54. List<Models.TvSerie> listFuture = akkaStreamFilesProcessing.getTvSerieByPrimaryTitle(tvseriePrimaryTitle);
  55. return new ResponseEntity<>(listFuture, HttpStatus.OK);
  56. }
  57. @RequestMapping(value = "/persons/tvseries/title/{tvSerieTitle}", method = RequestMethod.GET)
  58. private Future<IndexedSeq<Models.Person>> getPersonsForTvSerie(@PathVariable(name = "tvSerieTitle") String tvSerieTitle) {
  59. return akkaStreamFilesProcessing.getTeamOfPersonsForTvSerie(tvSerieTitle);
  60. }
  61. @RequestMapping(value = "/persons", method = RequestMethod.GET)
  62. private ResponseEntity<String> getAllPersons() {
  63. akkaStreamFilesProcessing.getAllPersons();
  64. return new ResponseEntity<>("is running", HttpStatus.OK);
  65. }
  66. @RequestMapping(value = "/tvseries", method = RequestMethod.GET)
  67. private ResponseEntity<String> getAllvSeries() {
  68. akkaStreamFilesProcessing.getAllTvSeries();
  69. return new ResponseEntity<>("is running", HttpStatus.OK);
  70. }
  71. }

Powered by TurnKey Linux.