diff --git a/app/CachetHq/Cachet/Controllers/Api/IncidentController.php b/app/CachetHq/Cachet/Controllers/Api/IncidentController.php index d6bebc26..b18bad0e 100644 --- a/app/CachetHq/Cachet/Controllers/Api/IncidentController.php +++ b/app/CachetHq/Cachet/Controllers/Api/IncidentController.php @@ -1,91 +1,91 @@ auth = $auth; - } + public function __construct(Shield $auth) { + $this->auth = $auth; + } - /** - * Get all incidents - * - * @return \Illuminate\Database\Eloquent\Collection - */ - public function getIncidents() { - return Incident::all(); - } + /** + * Get all incidents + * + * @return \Illuminate\Database\Eloquent\Collection + */ + public function getIncidents() { + return Incident::all(); + } - /** - * Get a single incident - * - * @param int $id - * - * @return Incident - */ - public function getIncident($id) { - if ($incident = Incident::find($id)) { - return $incident; - } else { - App::abort(404, 'Incident not found'); - } - } + /** + * Get a single incident + * + * @param int $id + * + * @return Incident + */ + public function getIncident($id) { + if ($incident = Incident::find($id)) { + return $incident; + } else { + App::abort(404, 'Incident not found'); + } + } - /** - * Create a new incident - * - * @return Incident - */ - public function postIncidents() { - $incident = new Incident(Input::all()); - $incident->user_id = $this->auth->user()->id; - return $this->_saveIncident($incident); - } + /** + * Create a new incident + * + * @return Incident + */ + public function postIncidents() { + $incident = new Incident(Input::all()); + $incident->user_id = $this->auth->user()->id; + return $this->_saveIncident($incident); + } - /** - * Update an existing incident - * - * @param int $id - * - * @return Incident - */ - public function putIncident($id) { - $incident = $this->getIncident($id); + /** + * Update an existing incident + * + * @param int $id + * + * @return Incident + */ + public function putIncident($id) { + $incident = $this->getIncident($id); - $incident->fill(Input::all()); + $incident->fill(Input::all()); - return $this->_saveIncident($incident); - } + return $this->_saveIncident($incident); + } - /** - * Function for saving the incident, and returning appropriate error codes - * - * @param Incident $incident - * - * @return Incident - */ - private function _saveIncident($incident) { - if ($incident->isValid()) { - try { - $component = $incident->parent; - if (!$component) { - App::abort(400, 'Invalid component specified'); - } + /** + * Function for saving the incident, and returning appropriate error codes + * + * @param Incident $incident + * + * @return Incident + */ + private function _saveIncident($incident) { + if ($incident->isValid()) { + try { + $component = $incident->parent; + if (!$component) { + App::abort(400, 'Invalid component specified'); + } - $incident->saveOrFail(); - return $incident; - } catch (Exception $e) { - App::abort(500, $e->getMessage()); - } - } else { - App::abort(404, $incident->getErrors()->first()); - } - } - } + $incident->saveOrFail(); + return $incident; + } catch (Exception $e) { + App::abort(500, $e->getMessage()); + } + } else { + App::abort(404, $incident->getErrors()->first()); + } + } +} \ No newline at end of file diff --git a/app/CachetHq/Cachet/Controllers/Api/MetricController.php b/app/CachetHq/Cachet/Controllers/Api/MetricController.php index 6a7a4b69..29f2a593 100644 --- a/app/CachetHq/Cachet/Controllers/Api/MetricController.php +++ b/app/CachetHq/Cachet/Controllers/Api/MetricController.php @@ -1,76 +1,76 @@ _saveMetric($metric); - } + /** + * Create a new metric + * + * @return Metric + */ + public function postMetrics() { + $metric = new Metric(Input::all()); + return $this->_saveMetric($metric); + } - /** - * Update an existing metric - * - * @param int $id - * - * @return Metric - */ - public function putMetric($id) { - $metric = $this->getMetric($id); - $metric->fill(Input::all()); - return $this->_saveMetric($metric); - } + /** + * Update an existing metric + * + * @param int $id + * + * @return Metric + */ + public function putMetric($id) { + $metric = $this->getMetric($id); + $metric->fill(Input::all()); + return $this->_saveMetric($metric); + } - /** - * Function for saving a metric, and returning appropriate error codes - * - * @param Metric $metric - * - * @return Metric - */ - private function _saveMetric($metric) { - if ($metric->isValid()) { - try { - $metric->saveOrFail(); - return $metric; - } catch (Exception $e) { - App::abort(500, $e->getMessage()); - } - } else { - App::abort(404, $metric->getErrors()->first()); - } - } - } + /** + * Function for saving a metric, and returning appropriate error codes + * + * @param Metric $metric + * + * @return Metric + */ + private function _saveMetric($metric) { + if ($metric->isValid()) { + try { + $metric->saveOrFail(); + return $metric; + } catch (Exception $e) { + App::abort(500, $e->getMessage()); + } + } else { + App::abort(404, $metric->getErrors()->first()); + } + } +} \ No newline at end of file diff --git a/app/transformers/IncidentTransformer.php b/app/transformers/IncidentTransformer.php index ab1f6b5f..5fbc46bf 100644 --- a/app/transformers/IncidentTransformer.php +++ b/app/transformers/IncidentTransformer.php @@ -1,19 +1,19 @@ parent; - $transformer = $component->getTransformer(); +class IncidentTransformer extends \League\Fractal\TransformerAbstract { + public function transform(Incident $incident) { + $component = $incident->parent; + $transformer = $component->getTransformer(); - return [ - 'id' => (int) $incident->id, - 'name' => $incident->name, - 'message' => $incident->message, - 'status_id' => (int) $incident->status, - 'status' => $incident->getHumanStatusAttribute(), - 'component' => $transformer->transform($component), - 'created_at' => $incident->created_at->timestamp, - 'updated_at' => $incident->updated_at->timestamp, - ]; - } - } + return [ + 'id' => (int) $incident->id, + 'name' => $incident->name, + 'message' => $incident->message, + 'status_id' => (int) $incident->status, + 'status' => $incident->getHumanStatusAttribute(), + 'component' => $transformer->transform($component), + 'created_at' => $incident->created_at->timestamp, + 'updated_at' => $incident->updated_at->timestamp, + ]; + } +} \ No newline at end of file diff --git a/app/transformers/MetricTransformer.php b/app/transformers/MetricTransformer.php index d1f2411a..3e8845bb 100644 --- a/app/transformers/MetricTransformer.php +++ b/app/transformers/MetricTransformer.php @@ -1,15 +1,15 @@ (int) $component->id, - 'name' => $component->name, - 'description' => $component->description, - 'suffix' => $component->suffix, - 'display' => $component->shouldDisplay, - 'created_at' => $component->created_at->timestamp, - 'updated_at' => $component->updated_at->timestamp, - ]; - } - } +class MetricTransformer extends \League\Fractal\TransformerAbstract { + public function transform(Metric $metric) { + return [ + 'id' => (int) $component->id, + 'name' => $component->name, + 'description' => $component->description, + 'suffix' => $component->suffix, + 'display' => $component->shouldDisplay, + 'created_at' => $component->created_at->timestamp, + 'updated_at' => $component->updated_at->timestamp, + ]; + } +} \ No newline at end of file