/** * @return string */ public function execute() { $photo = new Photo(); $photo->setTags($this->photoDTO->getTags()); $photo->setThumbnails($this->photoDTO->getUrls()); return $this->repository->store($photo); }
public function testInitialise() { $apiData = ["urls" => [Photo::THUMBNAIL_STANDARD => 'standardUrl', Photo::THUMBNAIL_SMALL => 'smallUrl'], "tags" => ['uno', 'duo']]; $photoDTO = new PhotoDTO($apiData['tags'], $apiData['urls']); $interactor = new AddPhoto($photoDTO, $this->repository); $photoId = $interactor->execute(); $photoDTO->setId($photoId); $actual = $this->repository->findById($photoId); $this->assertEquals($photoDTO->getId(), $actual->getId()); }
/** * @Route("/photos", name="api.photos.create") * @Method("POST") * @param Request $request * @return JsonResponse */ public function createPhotoAction(Request $request) { $content = json_decode($request->getContent()); $photoDTO = new PhotoDTO($content->tags, $content->urls); /** @var MongoDBPhotoRepository $photoRepository */ $photoRepository = $this->get('freyr.gallery.repository.photo'); $addPhotoInteractor = new AddPhoto($photoDTO, $photoRepository); $photoId = $addPhotoInteractor->execute(); $photoDTO->setId($photoId); return new JsonResponse($photoDTO); }