Add and remove metrics and metric points commands

This commit is contained in:
Joseph Cohen
2015-08-15 22:15:41 -05:00
committed by James Brooks
parent 64ff4d73c2
commit 9581c5a394
16 changed files with 489 additions and 26 deletions

View File

@@ -11,14 +11,19 @@
namespace CachetHQ\Cachet\Http\Controllers\Api;
use CachetHQ\Cachet\Commands\Metric\AddMetricCommand;
use CachetHQ\Cachet\Commands\Metric\RemoveMetricCommand;
use CachetHQ\Cachet\Models\Metric;
use Exception;
use GrahamCampbell\Binput\Facades\Binput;
use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Http\Request;
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
class MetricController extends AbstractApiController
{
use DispatchesJobs;
/**
* Get all metrics.
*
@@ -65,7 +70,15 @@ class MetricController extends AbstractApiController
public function postMetrics()
{
try {
$metric = Metric::create(Binput::all());
$metric = $this->dispatch(new AddMetricCommand(
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();
}
@@ -100,7 +113,7 @@ class MetricController extends AbstractApiController
*/
public function deleteMetric(Metric $metric)
{
$metric->delete();
$this->dispatch(new RemoveMetricCommand($metric));
return $this->noContent();
}