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);
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@ namespace CachetHQ\Cachet\Http\Controllers\Dashboard;
|
||||
use AltThree\Validator\ValidationException;
|
||||
use CachetHQ\Cachet\Commands\Metric\AddMetricCommand;
|
||||
use CachetHQ\Cachet\Commands\Metric\RemoveMetricCommand;
|
||||
use CachetHQ\Cachet\Commands\Metric\UpdateMetricCommand;
|
||||
use CachetHQ\Cachet\Models\Metric;
|
||||
use CachetHQ\Cachet\Models\MetricPoint;
|
||||
use GrahamCampbell\Binput\Facades\Binput;
|
||||
@@ -132,7 +133,16 @@ class MetricController extends Controller
|
||||
public function editMetricAction(Metric $metric)
|
||||
{
|
||||
try {
|
||||
$metric->update(Binput::get('metric', null, false));
|
||||
$this->dispatch(new UpdateMetricCommand(
|
||||
$metric,
|
||||
Binput::get('metric.name', null, false),
|
||||
Binput::get('metric.suffix', null, false),
|
||||
Binput::get('metric.description', null, false),
|
||||
Binput::get('metric.default_value', null, false),
|
||||
Binput::get('metric.calc_type', null, false),
|
||||
Binput::get('metric.display_chart', null, false),
|
||||
Binput::get('metric.places', null, false)
|
||||
));
|
||||
} catch (ValidationException $e) {
|
||||
return Redirect::route('dashboard.metrics.edit', ['id' => $metric->id])
|
||||
->withInput(Binput::all())
|
||||
|
||||
Reference in New Issue
Block a user