From aba2fb44d14ab0df412093ba4e6c5ff29a370a50 Mon Sep 17 00:00:00 2001 From: drigato Date: Mon, 3 Mar 2014 11:21:25 -0500 Subject: [PATCH] CC-5701: Airtime File API -put and delete actions working --- .../application/configs/application.ini | 1 + .../rest/controllers/MediaController.php | 33 ++++++++++--------- .../rest/views/scripts/media/delete.phtml | 0 .../rest/views/scripts/media/put.phtml | 0 4 files changed, 19 insertions(+), 15 deletions(-) create mode 100644 airtime_mvc/application/modules/rest/views/scripts/media/delete.phtml create mode 100644 airtime_mvc/application/modules/rest/views/scripts/media/put.phtml diff --git a/airtime_mvc/application/configs/application.ini b/airtime_mvc/application/configs/application.ini index 706beb249..71bcd5c46 100644 --- a/airtime_mvc/application/configs/application.ini +++ b/airtime_mvc/application/configs/application.ini @@ -7,6 +7,7 @@ appnamespace = "Application" resources.frontController.controllerDirectory = APPLICATION_PATH "/controllers" resources.frontController.params.displayExceptions = 0 resources.frontController.moduleDirectory = APPLICATION_PATH "/modules" +resources.frontController.plugins.putHandler = "Zend_Controller_Plugin_PutHandler" ;load everything in the modules directory including models resources.modules[] = "" resources.layout.layoutPath = APPLICATION_PATH "/layouts/scripts/" diff --git a/airtime_mvc/application/modules/rest/controllers/MediaController.php b/airtime_mvc/application/modules/rest/controllers/MediaController.php index e2759bd2e..6c59e1c55 100644 --- a/airtime_mvc/application/modules/rest/controllers/MediaController.php +++ b/airtime_mvc/application/modules/rest/controllers/MediaController.php @@ -54,11 +54,11 @@ class Rest_MediaController extends Zend_Rest_Controller $file->fromArray($this->getRequest()->getPost()); $file->save(); - $resp = $this->getResponse(); - $resp->setHttpResponseCode(201); - $resp->appendBody(json_encode($file->toArray())); + $this->getResponse() + ->setHttpResponseCode(201) + ->appendBody(json_encode($file->toArray())); } - + public function putAction() { if (!$this->verifyApiKey()) { @@ -70,17 +70,18 @@ class Rest_MediaController extends Zend_Rest_Controller } $file = CcFilesQuery::create()->findPk($id); - if ($show) + if ($file) { - $show->importFrom('JSON', $this->getRequest()->getRawBody()); - $show->save(); + $file->fromArray(json_decode($this->getRequest()->getRawBody(), true)); + $file->save(); $this->getResponse() - ->appendBody("From putAction() updating the requested show"); + ->setHttpResponseCode(200) + ->appendBody(json_encode($file->toArray())); } else { - $this->showNotFoundResponse(); + $this->fileNotFoundResponse(); } } - + public function deleteAction() { if (!$this->verifyApiKey()) { @@ -90,11 +91,13 @@ class Rest_MediaController extends Zend_Rest_Controller if (!$id) { return; } - $show = CcShowQuery::create()->$query->findPk($id); - if ($show) { - $show->delete(); + $file = CcFilesQuery::create()->findPk($id); + if ($file) { + $file->delete(); + $this->getResponse() + ->setHttpResponseCode(200); } else { - $this->showNotFoundResponse(); + $this->fileNotFoundResponse(); } } @@ -140,6 +143,6 @@ class Rest_MediaController extends Zend_Rest_Controller { $resp = $this->getResponse(); $resp->setHttpResponseCode(404); - $resp->appendBody("ERROR: Show not found."); + $resp->appendBody("ERROR: Media not found."); } } \ No newline at end of file diff --git a/airtime_mvc/application/modules/rest/views/scripts/media/delete.phtml b/airtime_mvc/application/modules/rest/views/scripts/media/delete.phtml new file mode 100644 index 000000000..e69de29bb diff --git a/airtime_mvc/application/modules/rest/views/scripts/media/put.phtml b/airtime_mvc/application/modules/rest/views/scripts/media/put.phtml new file mode 100644 index 000000000..e69de29bb