Пример #1
0
 public function addOrGetAction($json)
 {
     $trackDto = $this->parseJson($json);
     $userAlbum = $this->userAlbumRepository->find($trackDto->albumId);
     if ($userAlbum == null) {
         $this->logger->error("There is no user album with id = {$trackDto->albumId}.");
         throw new JsonException("Invalid id.");
     }
     if ($this->securityManager->getUser() !== $userAlbum->getUser()) {
         $this->logger->error("The user {$this->securityManager->getUser()} tried to access now own album with id = {$trackDto->albumId}.");
         throw new JsonException("Invalid id.");
     }
     $track = $this->userTrackRepository->findOneByUserAlbumAndTitle($userAlbum, $trackDto->title);
     if ($track == null) {
         return $this->addAction($json);
     } else {
         $dto = $this->trackHelper->convertUserTrackToDto($track);
         return new JsonViewModel($dto, $this->jsonUtils);
     }
 }