Create and update a metric.

This commit is contained in:
James Brooks
2014-11-25 21:35:52 +00:00
parent f71639f226
commit 39bc6a1648
4 changed files with 88 additions and 1 deletions

View File

@@ -155,4 +155,47 @@
}
}
/**
* Create a new metric
*
* @return Metric
*/
public function postIncidents() {
$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);
}
/**
* 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());
}
}
}