Esempio n. 1
0
 /**
  * {@inheritdoc}
  */
 public function validate(RestRequest $restRequest)
 {
     $this->setRepository($restRequest->getRepository());
     $this->setAllowExtraFields($restRequest->isAllowedExtraFields());
     $data = $restRequest->getData();
     $this->getForm(true)->submit($data);
     return $this->getForm()->isValid() ? $data : false;
 }
Esempio n. 2
0
 /**
  * {@inheritdoc}
  */
 public function deleteAction(RestRequest $restRequest, $id = null)
 {
     if ($id === null) {
         return $this->renderRest(['message' => $this->trans('response.error.id')], Response::HTTP_BAD_REQUEST);
     }
     $connection = $restRequest->getRepository()->getManager()->getConnection();
     $types = $restRequest->getRepository()->getTypes();
     try {
         if ($this->isBatch()) {
             $types = $restRequest->getRepository()->getTypes();
             $connection->bulk('delete', reset($types), ['_id' => $id]);
             $connection->commit(false);
         } else {
             $connection->delete(['id' => $id, 'type' => $types, 'index' => $connection->getIndexName()]);
         }
     } catch (Missing404Exception $e) {
         return $this->renderRest(['message' => $this->trans('response.error.not_found', ['%id%' => $id])], Response::HTTP_NOT_FOUND);
     }
     return $this->renderRest(null, Response::HTTP_NO_CONTENT);
 }