Added UpdateMetric and UpdateMetricPoint commands
This commit is contained in:
@@ -13,6 +13,7 @@ namespace CachetHQ\Cachet\Http\Controllers\Api;
|
||||
|
||||
use CachetHQ\Cachet\Commands\Metric\AddMetricCommand;
|
||||
use CachetHQ\Cachet\Commands\Metric\RemoveMetricCommand;
|
||||
use CachetHQ\Cachet\Commands\Metric\UpdateMetricCommand;
|
||||
use CachetHQ\Cachet\Models\Metric;
|
||||
use Exception;
|
||||
use GrahamCampbell\Binput\Facades\Binput;
|
||||
@@ -96,7 +97,16 @@ class MetricController extends AbstractApiController
|
||||
public function putMetric(Metric $metric)
|
||||
{
|
||||
try {
|
||||
$metric->update(Binput::all());
|
||||
$metric = $this->dispatch(new UpdateMetricCommand(
|
||||
$metric,
|
||||
Binput::get('name'),
|
||||
Binput::get('suffix'),
|
||||
Binput::get('description'),
|
||||
Binput::get('default_value'),
|
||||
Binput::get('calc_type', 0),
|
||||
Binput::get('display_chart'),
|
||||
Binput::get('places')
|
||||
));
|
||||
} catch (Exception $e) {
|
||||
throw new BadRequestHttpException();
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@ namespace CachetHQ\Cachet\Http\Controllers\Api;
|
||||
|
||||
use CachetHQ\Cachet\Commands\Metric\AddMetricPointCommand;
|
||||
use CachetHQ\Cachet\Commands\Metric\RemoveMetricPointCommand;
|
||||
use CachetHQ\Cachet\Commands\Metric\UpdateMetricPointCommand;
|
||||
use CachetHQ\Cachet\Models\Metric;
|
||||
use CachetHQ\Cachet\Models\MetricPoint;
|
||||
use Carbon\Carbon;
|
||||
@@ -48,7 +49,11 @@ class MetricPointController extends AbstractApiController
|
||||
public function postMetricPoints(Metric $metric)
|
||||
{
|
||||
try {
|
||||
$metricPoint = $this->dispatch(new AddMetricPointCommand($metric, Binput::get('value'), Binput::get('timestamp')));
|
||||
$metricPoint = $this->dispatch(new AddMetricPointCommand(
|
||||
$metric,
|
||||
Binput::get('value'),
|
||||
Binput::get('timestamp'))
|
||||
);
|
||||
} catch (Exception $e) {
|
||||
throw new BadRequestHttpException();
|
||||
}
|
||||
@@ -66,15 +71,12 @@ class MetricPointController extends AbstractApiController
|
||||
*/
|
||||
public function putMetricPoint(Metric $metric, MetricPoint $metricPoint)
|
||||
{
|
||||
$metricPointData = Binput::all();
|
||||
$metricPointData['metric_id'] = $metric->id;
|
||||
|
||||
if ($timestamp = array_pull($metricPointData, 'timestamp')) {
|
||||
$pointTimestamp = Carbon::createFromFormat('U', $timestamp);
|
||||
$metricPointData['created_at'] = $pointTimestamp->format('Y-m-d H:i:s');
|
||||
}
|
||||
|
||||
$metricPoint->update($metricPointData);
|
||||
$metricPoint = $this->dispatch(new UpdateMetricPointCommand(
|
||||
$metricPoint,
|
||||
$metric,
|
||||
Binput::get('value'),
|
||||
Binput::get('timestamp')
|
||||
));
|
||||
|
||||
return $this->item($metricPoint);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user