Skip to content

Commit

Permalink
Change status
Browse files Browse the repository at this point in the history
  • Loading branch information
Bukarinov committed Nov 26, 2012
1 parent c1f5a05 commit aec9a89
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions library/GeometriaLab/Api/Mvc/View/Http/CreateApiModelListener.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -4,15 +4,13 @@


use GeometriaLab\Model\ModelInterface, use GeometriaLab\Model\ModelInterface,
GeometriaLab\Model\CollectionInterface, GeometriaLab\Model\CollectionInterface,
GeometriaLab\Model\Schema\SchemaInterface,
GeometriaLab\Api\Mvc\View\Model\ApiModel, GeometriaLab\Api\Mvc\View\Model\ApiModel,
GeometriaLab\Api\Paginator\ModelPaginator, GeometriaLab\Api\Paginator\ModelPaginator,
GeometriaLab\Api\Exception\InvalidFieldsException, GeometriaLab\Api\Exception\InvalidFieldsException;
GeometriaLab\Api\Mvc\Controller\Action\Params\AbstractParams,
GeometriaLab\Api\Mvc\Controller\Action\Params\Schema\Property\IntegerProperty as ParamsIntegerProperty;


use Zend\Mvc\MvcEvent as ZendMvcEvent, use Zend\Mvc\MvcEvent as ZendMvcEvent,
Zend\Mvc\View\Http\InjectViewModelListener as ZendInjectViewModelListener, Zend\Mvc\View\Http\InjectViewModelListener as ZendInjectViewModelListener,
Zend\Http\PhpEnvironment\Response,
Zend\EventManager\ListenerAggregateInterface as ZendListenerAggregateInterface, Zend\EventManager\ListenerAggregateInterface as ZendListenerAggregateInterface,
Zend\EventManager\EventManagerInterface as ZendEvents, Zend\EventManager\EventManagerInterface as ZendEvents,
Zend\Validator\LessThan as ZendLessThanValidator, Zend\Validator\LessThan as ZendLessThanValidator,
Expand Down Expand Up @@ -78,9 +76,19 @@ public function createApiModel(ZendMvcEvent $e)
$apiModel->setVariable(ApiModel::FIELD_DATA, null); $apiModel->setVariable(ApiModel::FIELD_DATA, null);
} }


/* @var Response $response */
$response = $e->getResponse(); $response = $e->getResponse();
$apiException = $e->getParam('apiException', false); $apiException = $e->getParam('apiException', false);


if ($response->getStatusCode() === Response::STATUS_CODE_200) {
if ($apiModel->getVariable(ApiModel::FIELD_DATA) === null) {
$response->setStatusCode(Response::STATUS_CODE_204);
}
if ($e->getRouteMatch()->getParam('action') === 'create') {
$response->setStatusCode(Response::STATUS_CODE_201);
}
}

// set http code // set http code
$httpCode = $response->getStatusCode(); $httpCode = $response->getStatusCode();
$apiModel->setVariable(ApiModel::FIELD_HTTPCODE, $httpCode); $apiModel->setVariable(ApiModel::FIELD_HTTPCODE, $httpCode);
Expand Down

0 comments on commit aec9a89

Please sign in to comment.