1 | <?php |
||
17 | class WatchedMovieController extends BaseController |
||
18 | { |
||
19 | /** |
||
20 | * @Route("/api/guests/{token}/watchedMovies", methods={"POST"}); |
||
21 | * |
||
22 | * @param $token |
||
23 | * @param AddWatchedMovieRequest $addWatchedMovieRequest |
||
24 | * @param Request $request |
||
25 | * @param WatchedMovieService $watchedMovieService |
||
26 | * |
||
27 | * @throws \Exception |
||
28 | * |
||
29 | * @return JsonResponse |
||
30 | */ |
||
31 | 3 | public function postWatchedMovies($token, AddWatchedMovieRequest $addWatchedMovieRequest, Request $request, WatchedMovieService $watchedMovieService) |
|
32 | { |
||
33 | 3 | $em = $this->getDoctrine()->getManager(); |
|
34 | 3 | $guestSessionRepository = $em->getRepository(GuestSession::class); |
|
35 | |||
36 | /** @var $guestSession GuestSession|null */ |
||
37 | 3 | $guestSession = $guestSessionRepository->findOneBy([ |
|
38 | 3 | 'token' => $token, |
|
39 | ]); |
||
40 | |||
41 | 3 | if ($guestSession === null) { |
|
42 | throw new NotFoundHttpException('Guest session not found by provided token'); |
||
43 | } |
||
44 | |||
45 | 3 | $watchedMovieDTO = $addWatchedMovieRequest->getWatchedMovieDTO(); |
|
46 | 3 | $isMovieAdded = $watchedMovieService->addGuestWatchedMovie($guestSession, $watchedMovieDTO, $request->getLocale()); |
|
47 | |||
48 | if ($isMovieAdded === false) { |
||
49 | throw new NotFoundHttpException('Movie not found by provided ID / TMDB ID'); |
||
50 | } |
||
51 | |||
52 | return new JsonResponse(null, 202); |
||
53 | } |
||
54 | |||
55 | /** |
||
56 | * @Route("/api/guests/{id<\d+>}/watchedMovies", methods={"GET"}); |
||
57 | * |
||
58 | * @param Request $request |
||
59 | * @param GuestSession $guestSession |
||
60 | * |
||
61 | * @return JsonResponse |
||
62 | */ |
||
63 | public function getAll(Request $request, GuestSession $guestSession) |
||
82 | } |
||
83 |