Create and update a metric.
This commit is contained in:
@@ -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());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user