No Description

MovieController.java 3.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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.scheduling.annotation.Async;
  8. import org.springframework.web.bind.annotation.PathVariable;
  9. import org.springframework.web.bind.annotation.RequestMapping;
  10. import org.springframework.web.bind.annotation.RequestMethod;
  11. import org.springframework.web.bind.annotation.RestController;
  12. import scala.collection.IndexedSeq;
  13. import scala.concurrent.Future;
  14. import java.util.concurrent.CompletableFuture;
  15. import java.util.concurrent.ExecutionException;
  16. @SuppressWarnings("SpellCheckingInspection")
  17. @RestController
  18. public class MovieController {
  19. private final AkkaStreamFileProcessing akkaStreamFilesProcessing;
  20. public MovieController(AkkaStreamFileProcessing akkaStreamFilesProcessing) {
  21. this.akkaStreamFilesProcessing = akkaStreamFilesProcessing;
  22. }
  23. @RequestMapping(value = "/persons/id/{personID}", method = RequestMethod.GET)
  24. private ResponseEntity<String> getPersonByID(@PathVariable(name = "personID") String personID) throws ExecutionException, InterruptedException {
  25. Future<Models.Person> personFuture = akkaStreamFilesProcessing.getPersonById(personID);
  26. CompletableFuture<Models.Person> completableFutureResult =
  27. new CompletableFutureResult().buildcompletableFuture(personFuture);
  28. return new ResponseEntity<>(completableFutureResult.get().toString(), HttpStatus.OK);
  29. }
  30. @RequestMapping(value = "/persons/name/{primaryName}", method = RequestMethod.GET)
  31. private ResponseEntity<IndexedSeq<String>> getPersonByName(@PathVariable(name = "primaryName") String primaryName) throws ExecutionException, InterruptedException {
  32. Future<IndexedSeq<Models.Person>> personsFuture = akkaStreamFilesProcessing.getPersonByName(primaryName);
  33. CompletableFuture completableFutureResult =new
  34. CompletableFutureResult().buildCompletableFuture2(personsFuture);
  35. IndexedSeq<String> list = (IndexedSeq<String>) completableFutureResult.get();
  36. return new ResponseEntity<>(list, HttpStatus.OK);
  37. }
  38. @RequestMapping(value = "/tvseries/{tvseriePrimaryTitle}", method = RequestMethod.GET)
  39. private Future<IndexedSeq<Models.TvSeries>> getTvserieByPrimaryTitle(@PathVariable(name = "tvseriePrimaryTitle") String tvseriePrimaryTitle) {
  40. return akkaStreamFilesProcessing.getTvSerieByPrimaryTitle(tvseriePrimaryTitle);
  41. }
  42. @RequestMapping(value = "/tvseries/title/{tvSerieTitle}", method = RequestMethod.GET)
  43. @Async
  44. private Future<IndexedSeq<Models.Person>> getPersonsForTvSerie(@PathVariable(name = "tvSerieTitle") String tvSerieTitle) {
  45. return akkaStreamFilesProcessing.getTeamOfPersonsForTvSerie(tvSerieTitle);
  46. }
  47. @RequestMapping(value = "/persons", method = RequestMethod.GET)
  48. private ResponseEntity<String> getAllPersons() {
  49. akkaStreamFilesProcessing.getAllPersons();
  50. return new ResponseEntity<>("is running", HttpStatus.OK);
  51. }
  52. @RequestMapping(value = "/tvseries", method = RequestMethod.GET)
  53. private ResponseEntity<String> getAllvSeries() {
  54. akkaStreamFilesProcessing.getAllTvSeries();
  55. return new ResponseEntity<>("is running", HttpStatus.OK);
  56. }
  57. }

Powered by TurnKey Linux.