public function postAction(Request $request, $documentId = null)
    {
        $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
            );
        }
        if (!empty($documentId)) {
            $data['_id'] = $documentId;
        }

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

        $documentId = $response['items'][0]['create']['_id'];
        $row = $this->getCrudService()->read($repository, $documentId);
        return $this->renderRest($request, $row, Response::HTTP_CREATED);
    }
public function postAction(Request $request, $documentId = null)
    {
        $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
            );
        }
        if (!empty($documentId)) {
            $data['_id'] = $documentId;
        }

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

        $documentId = $response['items'][0]['create']['_id'];
        $row = $this->getCrudService()->read($repository, $documentId);
        return $this->renderRest($request, $row, Response::HTTP_CREATED);
    }
{@inheritdoc}