|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Actors\Controller; |
|
4
|
|
|
|
|
5
|
|
|
use App\Controller\BaseController; |
|
6
|
|
|
use App\Movies\Entity\MovieActor; |
|
7
|
|
|
use App\Movies\Repository\MovieActorRepository; |
|
8
|
|
|
use App\Movies\Repository\MovieRepository; |
|
9
|
|
|
use App\Pagination\PaginatedCollection; |
|
10
|
|
|
use Symfony\Component\HttpFoundation\JsonResponse; |
|
11
|
|
|
use Symfony\Component\HttpFoundation\Request; |
|
12
|
|
|
use Symfony\Component\Routing\Annotation\Route; |
|
13
|
|
|
|
|
14
|
|
|
class ActorMovieController extends BaseController |
|
15
|
|
|
{ |
|
16
|
|
|
/** |
|
17
|
|
|
* @Route("/api/actors/{id}/movies", methods={"GET"}, requirements={"id"="\d+"}) |
|
18
|
|
|
* |
|
19
|
|
|
* @param Request $request |
|
20
|
|
|
* @param int $id |
|
21
|
|
|
* @param MovieActorRepository $repository |
|
22
|
|
|
* @param MovieRepository $movieRepository |
|
23
|
|
|
* |
|
24
|
|
|
* @return JsonResponse |
|
25
|
|
|
*/ |
|
26
|
|
|
public function getActorsMovies(Request $request, int $id, MovieActorRepository $repository, MovieRepository $movieRepository) |
|
27
|
|
|
{ |
|
28
|
|
|
$movieActors = $repository->findAllByActor($id); |
|
29
|
|
|
$moviesIds = array_map(function (MovieActor $movieActor) { |
|
30
|
|
|
return $movieActor->getMovie()->getId(); |
|
31
|
|
|
}, $movieActors->getResult()); |
|
32
|
|
|
|
|
33
|
|
|
if (null === $user = $this->getUser()) { |
|
34
|
|
|
$actors = $movieRepository->findAllByIdsQuery($moviesIds); |
|
35
|
|
|
} else { |
|
36
|
|
|
$actors = $movieRepository->findAllByIdsWithIsWatchedFlag($moviesIds, $user->getId()); |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
$offset = (int) $request->get('offset', 0); |
|
40
|
|
|
$limit = $request->get('limit', null); |
|
41
|
|
|
|
|
42
|
|
|
$collection = new PaginatedCollection($actors, $offset, $limit); |
|
43
|
|
|
|
|
44
|
|
|
return $this->response($collection, 200, [], [ |
|
45
|
|
|
'groups' => ['list'], |
|
46
|
|
|
]); |
|
47
|
|
|
} |
|
48
|
|
|
} |
|
49
|
|
|
|