/** * Delete an filter with the given id. * * @param Request $request * * @return \Symfony\Component\HttpFoundation\Response */ public function cdeleteAction(Request $request) { $ids = explode(',', $request->get('ids')); if ($ids && count($ids) > 0) { try { $this->getManager()->batchDelete($ids); $view = $this->view($ids, 204); } catch (FilterNotFoundException $exc) { $exception = new EntityNotFoundException($exc->getEntityName(), $exc->getId()); $view = $this->view($exception->toArray(), 404); } } else { $exception = new InvalidArgumentException(static::$entityName, $ids); $view = $this->view($exception->toArray(), 400); } return $this->handleView($view); }
/** * Returns the response with the entity with the given id, or a response with a status of 404, in case the entity * is not found. The find method is injected by a callback. * * @param $id * @param callback $findCallback * * @return \Symfony\Component\HttpFoundation\Response */ protected function responseGetById($id, $findCallback) { $entity = $findCallback($id); if (!$entity) { $exception = new EntityNotFoundException(self::$entityName, $id); // Return a 404 together with an error message, given by the exception, if the entity is not found $view = $this->view($exception->toArray(), 404); } else { $view = $this->view($entity, 200); } return $view; }
/** * @Post("/shippings/{id}") */ public function postTriggerAction($id, Request $request) { $status = $request->get('action'); $em = $this->getDoctrine()->getManager(); try { $shipping = $this->getManager()->findByIdAndLocale($id, $this->getLocale($request)); switch ($status) { case 'deliverynote': $this->getManager()->convertStatus($shipping, ShippingStatus::STATUS_DELIVERY_NOTE); break; case 'edit': $this->getManager()->convertStatus($shipping, ShippingStatus::STATUS_CREATED); break; case 'ship': $this->getManager()->convertStatus($shipping, ShippingStatus::STATUS_SHIPPED); break; case 'cancel': $this->getManager()->convertStatus($shipping, ShippingStatus::STATUS_CANCELED); break; default: throw new RestException("Unrecognized status: " . $status); } $em->flush(); $view = $this->view($shipping, 200); } catch (OrderNotFoundException $exc) { $exception = new EntityNotFoundException($exc->getEntityName(), $exc->getId()); $view = $this->view($exception->toArray(), 404); } return $this->handleView($view); }
/** * POST Route annotation. * * @Post("/tags/merge") * * @param \Symfony\Component\HttpFoundation\Request $request * * @return \Symfony\Component\HttpFoundation\Response */ public function postMergeAction(Request $request) { try { $srcTagIds = explode(',', $request->get('src')); $destTagId = $request->get('dest'); $destTag = $this->getManager()->merge($srcTagIds, $destTagId); $view = $this->view(null, 303, ['location' => $destTag->getLinks()['self']]); } catch (TagNotFoundException $exc) { $entityNotFoundException = new EntityNotFoundException(self::$entityName, $exc->getId()); $view = $this->view($entityNotFoundException->toArray(), 404); } return $this->handleView($view); }
/** * Triggers actions like status conversion. * * @Post("/orders/{id}") * * @param $id * @param Request $request * * @throws EntityNotFoundException * @throws RestException * * @return Response */ public function postTriggerAction($id, Request $request) { $status = $request->get('action'); $em = $this->getDoctrine()->getManager(); try { $order = $this->getManager()->findByIdAndLocale($id, $this->getLocale($request)); if (!$order) { throw new OrderNotFoundException($id); } switch ($status) { case 'confirm': $this->getManager()->convertStatus($order, OrderStatus::STATUS_CONFIRMED); break; case 'edit': $this->getManager()->convertStatus($order, OrderStatus::STATUS_CREATED); break; default: throw new RestException("Unrecognized status: " . $status); } $em->flush(); $view = $this->view($order, 200); } catch (OrderNotFoundException $exc) { $exception = new EntityNotFoundException($exc->getEntityName(), $exc->getId()); $view = $this->view($exception->toArray(), 404); } return $this->handleView($view); }
/** * @param Request $request * @param integer $eventId * @return \Symfony\Component\HttpFoundation\Response */ public function putAction(Request $request, $eventId) { try { $event = $this->getManager()->save($request->request->all(), $this->getLocale($request), $eventId); $view = $this->view($event, 200); } catch (EventNotFoundException $exc) { $exception = new EntityNotFoundException($exc->getEntityName(), $exc->getId()); $view = $this->view($exception->toArray(), 404); } catch (EventDependencyNotFoundException $exc) { $exception = new EntityNotFoundException($exc->getEntityName(), $exc->getId()); $view = $this->view($exception->toArray(), 400); } return $this->handleView($view); }