diff --git a/app/controllers/ApiController.php b/app/controllers/ApiController.php index 3364a174..6f1771e9 100644 --- a/app/controllers/ApiController.php +++ b/app/controllers/ApiController.php @@ -44,18 +44,24 @@ public function postComponents() { $component = new Component(Input::all()); $component->user_id = $this->auth->user()->id; - if ($component->isValid()) { - try { - $component->saveOrFail(); - return $component; - } catch (Exception $e) { - App::abort(500, $e->getMessage()); - } - } else { - App::abort(404, $component->getErrors()->first()); - } + return $this->_saveComponent($component); } + /** + * Update an existing component + * + * @param int $id + * + * @return Component + */ + public function putComponent($id) { + $component = $this->getComponent($id); + + $component->fill(Input::all()); + + return $this->_saveComponent($component); + } + /** * Get all incidents * @@ -130,6 +136,26 @@ } } + /** + * Function for saving the component, and returning appropriate error codes + * + * @param Component $component + * + * @return Component + */ + private function _saveComponent($component) { + if ($component->isValid()) { + try { + $component->saveOrFail(); + return $component; + } catch (Exception $e) { + App::abort(500, $e->getMessage()); + } + } else { + App::abort(404, $component->getErrors()->first()); + } + } + /** * Function for saving the incident, and returning appropriate error codes * diff --git a/app/routes/api.php b/app/routes/api.php index 397ab254..c1a901d6 100644 --- a/app/routes/api.php +++ b/app/routes/api.php @@ -14,6 +14,7 @@ Route::post('components', 'ApiController@postComponents'); Route::post('incidents', 'ApiController@postIncidents'); + Route::put('components/{id}', 'ApiController@putComponent'); Route::put('incidents/{id}', 'ApiController@putIncident'); }); diff --git a/app/transformers/ComponentTransformer.php b/app/transformers/ComponentTransformer.php index 46b619f5..ca2e3ad9 100644 --- a/app/transformers/ComponentTransformer.php +++ b/app/transformers/ComponentTransformer.php @@ -7,7 +7,7 @@ 'name' => $component->name, 'description' => $component->description, 'status_id' => (int) $component->status, - 'status' => $component->getHumanStatusAttribute(), + 'status' => $component->humanStatus, 'incident_count' => $component->incidents()->count(), 'created_at' => $component->created_at->timestamp, 'updated_at' => $component->updated_at->timestamp,