/** * @ApiDoc( * description="New Photo", * statusCodes={201="Photo"}, * section="Photo", * parameters={ * {"name"="uploadedPicture", "dataType"="string", "required"=false }, * {"name"="restaurant[id]", "dataType"="integer", "required"=true }, * }) * @Route("/api/photos") * @Method({"POST"}) * @return View */ public function newAction() { $user = $this->getUser(); /** @var Photo $photo */ $photo = $this->deserializeCreateRequest(Photo::CLASS_NAME); $photo->setUser($user); if ($photo->getUploadedPicture()) { $pictureFilename = $this->s3Client->uploadBase64($photo->getUploadedPicture(), 'photos/', 'jpg', 1080, 1080); $photo->setSrc($pictureFilename); $thumbFilename = $this->s3Client->uploadBase64($photo->getUploadedPicture(), 'photos_thumb/', 'jpg', 200, 200); $photo->setThumb($thumbFilename); } $this->validate($photo); $this->entityManager->persist($photo); $this->entityManager->flush(); $this->dispatch(ApiEvent::PHOTO_CREATED, new PhotoCreatedEvent($photo, $this->getUser())); $this->cacheManager->invalidateOnInsert($photo); return $this->view(array('photo' => $photo), 201); }
/** * @ApiDoc( * description="Update Restaurant", * statusCodes={200="Restaurant"}, * section="Restaurant") * @Route("/api/restaurants/{id}") * @Method({"PUT"}) * @return View */ public function updateAction() { $restaurant = $this->deserializeUpdateRequest(Restaurant::CLASS_NAME); $this->securityCheck(Permission::WRITE, $restaurant); // @TODO move this to restaurant manager if ($restaurant->getUploadedPicture()) { $pictureFilename = $this->s3Client->uploadBase64($restaurant->getUploadedPicture(), 'restaurant/', 'jpg', 640, 380); $restaurant->setPicture($pictureFilename); $thumbFilename = $this->s3Client->uploadBase64($restaurant->getUploadedPicture(), 'restaurant_thumb/', 'jpg', 200, 200); $restaurant->setThumb($thumbFilename); } $this->validate($restaurant); $this->entityManager->flush(); $this->cacheManager->invalidateOnUpdate($restaurant); return $this->view(array('restaurant' => $restaurant)); }