Controller/RestController.php
public function putAction(Request $request, $documentId)
    {
        $repository = $this->getRequestRepository($request);
        $data = $this->get('ongr_api.request_serializer')->deserializeRequest($request);

        $validation = $this->get('ongr_api.field_validator')
            ->validateFields(
                $request,
                $repository,
                $data
            );

        if (isset($validation['message'])) {
            return $this->renderError(
                $request,
                $validation['message'],
                Response::HTTP_NOT_ACCEPTABLE
            );
        }

        try {
            $this->getCrudService()->update($repository, $documentId, $data);
            $response = $this->getCrudService()->commit($repository);
        } catch (\RuntimeException $e) {
            return $this->renderError($request, $e->getMessage(), Response::HTTP_BAD_REQUEST);
        } catch (NoDocumentsToGetException $e) {
            return $this->renderError($request, $e->getMessage(), Response::HTTP_NOT_FOUND);
        } catch (\Exception $e) {
            return $this->renderError($request, $e->getMessage(), Response::HTTP_BAD_REQUEST);
        }

        $documentId = $response['items'][0]['update']['_id'];
        $row = $this->getCrudService()->read($repository, $documentId);

        return $this->renderRest($request, $row, Response::HTTP_NO_CONTENT);
    }
public function putAction(Request $request, $documentId)
    {
        $repository = $this->getRequestRepository($request);
        $data = $this->get('ongr_api.request_serializer')->deserializeRequest($request);

        $validation = $this->get('ongr_api.field_validator')
            ->validateFields(
                $request,
                $repository,
                $data
            );

        if (isset($validation['message'])) {
            return $this->renderError(
                $request,
                $validation['message'],
                Response::HTTP_NOT_ACCEPTABLE
            );
        }

        try {
            $this->getCrudService()->update($repository, $documentId, $data);
            $response = $this->getCrudService()->commit($repository);
        } catch (\RuntimeException $e) {
            return $this->renderError($request, $e->getMessage(), Response::HTTP_BAD_REQUEST);
        } catch (NoDocumentsToGetException $e) {
            return $this->renderError($request, $e->getMessage(), Response::HTTP_NOT_FOUND);
        } catch (\Exception $e) {
            return $this->renderError($request, $e->getMessage(), Response::HTTP_BAD_REQUEST);
        }

        $documentId = $response['items'][0]['update']['_id'];
        $row = $this->getCrudService()->read($repository, $documentId);

        return $this->renderRest($request, $row, Response::HTTP_NO_CONTENT);
    }
public function putAction ( Request $ request , $ documentId ) { $ repository = $ this -> getRequestRepository ( $ request ) ; $ data = $ this -> get ( 'ongr_api.request_serializer' ) -> deserializeRequest ( $ request ) ; $ validation = $ this -> get ( 'ongr_api.field_validator' ) -> validateFields ( $ request , $ repository , $ data ) ; if ( isset ( $ validation [ 'message' ] ) ) { return $ this -> renderError ( $ request , $ validation [ 'message' ] , Response :: HTTP_NOT_ACCEPTABLE ) ; } try { $ this -> getCrudService ( ) -> update ( $ repository , $ documentId , $ data ) ; $ response = $ this -> getCrudService ( ) -> commit ( $ repository ) ; } catch ( \ RuntimeException $ e ) { return $ this -> renderError ( $ request , $ e -> getMessage ( ) , Response :: HTTP_BAD_REQUEST ) ; } catch ( NoDocumentsToGetException $ e ) { return $ this -> renderError ( $ request , $ e -> getMessage ( ) , Response :: HTTP_NOT_FOUND ) ; } catch ( \ Exception $ e ) { return $ this -> renderError ( $ request , $ e -> getMessage ( ) , Response :: HTTP_BAD_REQUEST ) ; } $ documentId = $ response [ 'items' ] [ 0 ] [ 'update' ] [ '_id' ] ; $ row = $ this -> getCrudService ( ) -> read ( $ repository , $ documentId ) ; return $ this -> renderRest ( $ request , $ row , Response :: HTTP_NO_CONTENT ) ; }
{@inheritdoc}
{