| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970 |
- package fr.natan.akkastreamfileprocessingapi.controller;
-
- import fr.natan.akkastreamfileprocessingapi.futurecompleteness.CompletableFutureResult;
- import fr.natan.akkastreamfileprocessingapi.models.Models;
- import fr.natan.akkastreamfileprocessingapi.service.AkkaStreamFileProcessing;
- import org.springframework.http.HttpStatus;
- import org.springframework.http.ResponseEntity;
- import org.springframework.scheduling.annotation.Async;
- import org.springframework.web.bind.annotation.PathVariable;
- import org.springframework.web.bind.annotation.RequestMapping;
- import org.springframework.web.bind.annotation.RequestMethod;
- import org.springframework.web.bind.annotation.RestController;
- import scala.collection.IndexedSeq;
- import scala.concurrent.Future;
-
- import java.util.concurrent.CompletableFuture;
- import java.util.concurrent.ExecutionException;
-
-
- @SuppressWarnings("SpellCheckingInspection")
- @RestController
- public class MovieController {
-
- private final AkkaStreamFileProcessing akkaStreamFilesProcessing;
-
- public MovieController(AkkaStreamFileProcessing akkaStreamFilesProcessing) {
- this.akkaStreamFilesProcessing = akkaStreamFilesProcessing;
- }
-
- @RequestMapping(value = "/persons/id/{personID}", method = RequestMethod.GET)
- private ResponseEntity<String> getPersonByID(@PathVariable(name = "personID") String personID) throws ExecutionException, InterruptedException {
- Future<Models.Person> personFuture = akkaStreamFilesProcessing.getPersonById(personID);
- CompletableFuture<Models.Person> completableFutureResult =
- new CompletableFutureResult().buildcompletableFuture(personFuture);
-
- return new ResponseEntity<>(completableFutureResult.get().toString(), HttpStatus.OK);
- }
-
- @RequestMapping(value = "/persons/name/{primaryName}", method = RequestMethod.GET)
- private ResponseEntity<IndexedSeq<String>> getPersonByName(@PathVariable(name = "primaryName") String primaryName) throws ExecutionException, InterruptedException {
- Future<IndexedSeq<Models.Person>> personsFuture = akkaStreamFilesProcessing.getPersonByName(primaryName);
- CompletableFuture completableFutureResult =new
- CompletableFutureResult().buildCompletableFuture2(personsFuture);
- IndexedSeq<String> list = (IndexedSeq<String>) completableFutureResult.get();
- return new ResponseEntity<>(list, HttpStatus.OK);
- }
-
- @RequestMapping(value = "/tvseries/{tvseriePrimaryTitle}", method = RequestMethod.GET)
- private Future<IndexedSeq<Models.TvSeries>> getTvserieByPrimaryTitle(@PathVariable(name = "tvseriePrimaryTitle") String tvseriePrimaryTitle) {
- return akkaStreamFilesProcessing.getTvSerieByPrimaryTitle(tvseriePrimaryTitle);
- }
-
- @RequestMapping(value = "/tvseries/title/{tvSerieTitle}", method = RequestMethod.GET)
- @Async
- private Future<IndexedSeq<Models.Person>> getPersonsForTvSerie(@PathVariable(name = "tvSerieTitle") String tvSerieTitle) {
- return akkaStreamFilesProcessing.getTeamOfPersonsForTvSerie(tvSerieTitle);
- }
-
- @RequestMapping(value = "/persons", method = RequestMethod.GET)
- private ResponseEntity<String> getAllPersons() {
- akkaStreamFilesProcessing.getAllPersons();
- return new ResponseEntity<>("is running", HttpStatus.OK);
- }
-
- @RequestMapping(value = "/tvseries", method = RequestMethod.GET)
- private ResponseEntity<String> getAllvSeries() {
- akkaStreamFilesProcessing.getAllTvSeries();
- return new ResponseEntity<>("is running", HttpStatus.OK);
- }
- }
|