CC-5701: Airtime File API

-put and delete actions working
This commit is contained in:
drigato 2014-03-03 11:21:25 -05:00
parent 64c1dd2c1e
commit aba2fb44d1
4 changed files with 19 additions and 15 deletions

View File

@ -7,6 +7,7 @@ appnamespace = "Application"
resources.frontController.controllerDirectory = APPLICATION_PATH "/controllers" resources.frontController.controllerDirectory = APPLICATION_PATH "/controllers"
resources.frontController.params.displayExceptions = 0 resources.frontController.params.displayExceptions = 0
resources.frontController.moduleDirectory = APPLICATION_PATH "/modules" resources.frontController.moduleDirectory = APPLICATION_PATH "/modules"
resources.frontController.plugins.putHandler = "Zend_Controller_Plugin_PutHandler"
;load everything in the modules directory including models ;load everything in the modules directory including models
resources.modules[] = "" resources.modules[] = ""
resources.layout.layoutPath = APPLICATION_PATH "/layouts/scripts/" resources.layout.layoutPath = APPLICATION_PATH "/layouts/scripts/"

View File

@ -54,11 +54,11 @@ class Rest_MediaController extends Zend_Rest_Controller
$file->fromArray($this->getRequest()->getPost()); $file->fromArray($this->getRequest()->getPost());
$file->save(); $file->save();
$resp = $this->getResponse(); $this->getResponse()
$resp->setHttpResponseCode(201); ->setHttpResponseCode(201)
$resp->appendBody(json_encode($file->toArray())); ->appendBody(json_encode($file->toArray()));
} }
public function putAction() public function putAction()
{ {
if (!$this->verifyApiKey()) { if (!$this->verifyApiKey()) {
@ -70,17 +70,18 @@ class Rest_MediaController extends Zend_Rest_Controller
} }
$file = CcFilesQuery::create()->findPk($id); $file = CcFilesQuery::create()->findPk($id);
if ($show) if ($file)
{ {
$show->importFrom('JSON', $this->getRequest()->getRawBody()); $file->fromArray(json_decode($this->getRequest()->getRawBody(), true));
$show->save(); $file->save();
$this->getResponse() $this->getResponse()
->appendBody("From putAction() updating the requested show"); ->setHttpResponseCode(200)
->appendBody(json_encode($file->toArray()));
} else { } else {
$this->showNotFoundResponse(); $this->fileNotFoundResponse();
} }
} }
public function deleteAction() public function deleteAction()
{ {
if (!$this->verifyApiKey()) { if (!$this->verifyApiKey()) {
@ -90,11 +91,13 @@ class Rest_MediaController extends Zend_Rest_Controller
if (!$id) { if (!$id) {
return; return;
} }
$show = CcShowQuery::create()->$query->findPk($id); $file = CcFilesQuery::create()->findPk($id);
if ($show) { if ($file) {
$show->delete(); $file->delete();
$this->getResponse()
->setHttpResponseCode(200);
} else { } else {
$this->showNotFoundResponse(); $this->fileNotFoundResponse();
} }
} }
@ -140,6 +143,6 @@ class Rest_MediaController extends Zend_Rest_Controller
{ {
$resp = $this->getResponse(); $resp = $this->getResponse();
$resp->setHttpResponseCode(404); $resp->setHttpResponseCode(404);
$resp->appendBody("ERROR: Show not found."); $resp->appendBody("ERROR: Media not found.");
} }
} }