/** * @return string */ public function execute() { $photo = new Photo(); $photo->setTags($this->photoDTO->getTags()); $photo->setThumbnails($this->photoDTO->getUrls()); return $this->repository->store($photo); }
/** * TODO: consider refactor * @return Photo */ protected function addRandomPhoto() { $tags = [['name' => ' tag'], ['name' => 'tag '], ['name' => ' tag '], ['name' => 'tag']]; $data = ['name' => uniqid('name'), 'url' => uniqid('url'), 'tags' => $tags, 'gallery' => ['name' => ' Gallery: Gallery1 ']]; $photo = new Photo($data); $photoId = $this->repository->store($photo); $photo->setId($photoId); return $photo; }
/** * @return GetPhotosDTO */ public function execute() { $photos = $this->repository->findPhotosByTags($this->tags); $response = new GetPhotosDTO(); foreach ($photos as $photo) { $photoResponse = new GetPhotoDTO(); $photoResponse->smallUrl = $photo->getUrl(Photo::THUMBNAIL_SMALL); $photoResponse->standardUrl = $photo->getUrl(Photo::THUMBNAIL_STANDARD); $photoResponse->tags = $photo->getTagsAsArray(); $photoResponse->id = $photo->getId(); $response->photos[] = $photoResponse; } return $response; }
/** * @return GetPhotoDTO * @throws PhotoNotFoundException */ public function execute() { try { $photo = $this->repository->findById($this->photoId); $response = new GetPhotoDTO(); $response->smallUrl = $photo->getUrl(Photo::THUMBNAIL_SMALL); $response->standardUrl = $photo->getUrl(Photo::THUMBNAIL_STANDARD); $response->tags = $photo->getTagsAsArray(); $response->id = $photo->getId(); return $response; } catch (\InvalidArgumentException $exception) { throw new PhotoNotFoundException($this->photoId, $exception); } }
/** * @return GetTagsDTO */ public function execute() { $tags = $this->repository->findAllTags(); foreach ($tags as $tag) { $tag->setCoverPhoto(new CoverPhoto($this->repository->getRandomPhotoFromTag($tag))); } $response = new GetTagsDTO(); foreach ($tags as $tag) { $tagResponse = new TagDTO(); $tagResponse->name = $tag->getName(); $coverPhotoResponse = new CoverPhotoDTO(); $coverPhotoResponse->url = $tag->getCoverPhoto()->getUrl(); $tagResponse->coverPhoto = $coverPhotoResponse; $response->tags[] = $tagResponse; } return $response; }