| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586 |
- 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.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 play.api.libs.json.JsValue;
- import play.api.libs.json.Json;
- import scala.collection.IndexedSeq;
- import scala.collection.immutable.List;
- import scala.concurrent.Future;
-
- import java.util.concurrent.CompletableFuture;
- import java.util.concurrent.ExecutionException;
-
-
- @SuppressWarnings("SpellCheckingInspection")
- @RestController
- public class MovieController {
-
- private final AkkaStreamFileProcessing akkaStreamFilesProcessing;
- private final CompletableFutureResult completableFutureResult;
- public MovieController(AkkaStreamFileProcessing akkaStreamFilesProcessing) {
- this.akkaStreamFilesProcessing = akkaStreamFilesProcessing;
- completableFutureResult = new CompletableFutureResult();
- }
-
- @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> personCompletableFuture = this.completableFutureResult.buildcompletableFuture(personFuture);
- Models.Person person = personCompletableFuture.get();
- JsValue personJs = Json.toJson(person, person.personFormat());
- return new ResponseEntity<>(personJs.toString(), HttpStatus.OK);
- }
-
- @RequestMapping(value = "/persons/name/{primaryName}", method = RequestMethod.GET)
- private ResponseEntity<String> getPersonByName(@PathVariable(name = "primaryName") String primaryName)
- throws ExecutionException, InterruptedException {
-
- Future<Models.Person> personFuture = akkaStreamFilesProcessing.getPersonByName(primaryName);
- CompletableFuture completableFutureResult = this.completableFutureResult.buildcompletableFuture(personFuture);
- Models.Person person = (Models.Person) completableFutureResult.get();
- JsValue personJs = Json.toJson(person, person.personFormat());
- return new ResponseEntity<>(personJs.toString(), HttpStatus.OK);
- }
-
- @RequestMapping(value = "/tvseries/id/{tvSerieId}", method = RequestMethod.GET)
- private ResponseEntity<String> getTvSerieByID(@PathVariable(name = "tvSerieId") String tvSerieID) throws ExecutionException, InterruptedException {
- Future<Models.TvSerie> tvSerieFuture = akkaStreamFilesProcessing.getTvSerieById(tvSerieID);
- CompletableFuture<Models.TvSerie> tvSerieCompletableFuture = this.completableFutureResult.buildcompletableFuture(tvSerieFuture);
- Models.TvSerie tvSerie = tvSerieCompletableFuture.get();
- JsValue tvSerieJs = Json.toJson(tvSerie, tvSerie.tvSerieFormat());
-
- return new ResponseEntity<>(tvSerieJs.toString(), HttpStatus.OK);
- }
-
- @RequestMapping(value = "/tvseries/title/{tvseriePrimaryTitle}", method = RequestMethod.GET)
- private ResponseEntity<List<Models.TvSerie>> getTvserieByPrimaryTitle(@PathVariable(name = "tvseriePrimaryTitle") String tvseriePrimaryTitle) {
- List<Models.TvSerie> listFuture = akkaStreamFilesProcessing.getTvSerieByPrimaryTitle(tvseriePrimaryTitle);
-
- return new ResponseEntity<>(listFuture, HttpStatus.OK);
- }
-
- @RequestMapping(value = "/persons/tvseries/title/{tvSerieTitle}", method = RequestMethod.GET)
- 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);
- }
- }
|