/**
  * @param Command|GetTrackCommand $command
  *
  * @return mixed
  * @throws TrackNotFoundException
  */
 public function handle(Command $command)
 {
     $track = $this->trackRepository->find($command->trackId());
     if (!$track) {
         throw new TrackNotFoundException($command->trackId());
     }
     return $this->getTrackCommandResultDataTransformer->transform(GetTrackCommandResult::instance($track));
 }
 /**
  * @param Command|CreateTrackCommand $command
  *
  * @return mixed
  */
 public function handle(Command $command)
 {
     $album = $this->albumRepository->find($command->albumId());
     $genre = $this->genreRepository->find($command->genreId());
     $mediaType = $this->mediaTypeRepository->find($command->mediaTypeId());
     $playList = $this->playListRepository->find($command->playListId());
     $track = Track::instance($command->name(), $album)->setComposer($command->composer())->setBytes($command->bytes())->setMilliseconds($command->milliseconds())->setGenre($genre)->setMediaType($mediaType)->setUnitPrice($command->unitPrice());
     $this->trackRepository->save($track);
     $playList->addTrack($track);
     $this->playListRepository->save($playList);
     return $this->dataTransformer->transform(CreateTrackCommandResult::instance($track));
 }
 /**
  * @param Command|SearchTracksCommand $command
  *
  * @return mixed
  * @throws TrackNotFoundException
  */
 public function handle(Command $command)
 {
     $from = ($command->page() - 1) * TrackRepository::SIZE;
     $tracks = $this->trackRepository->findByCriteria(TrackRepositoryCriteria::instance($command->albumId(), $command->albumTitle(), $command->trackName(), $command->composer(), $command->page(), ['id' => 'asc'], TrackRepository::SIZE, $from));
     return $this->searchTracksCommandResultDataTransformer->transform(SearchTracksCommandResult::instance($tracks));
 }