Cachet/app/Http/Controllers/Api/MetricController.php

111 lines
2.4 KiB
PHP
Raw Normal View History

<?php
2014-11-26 16:08:47 +00:00
/*
* This file is part of Cachet.
*
* (c) James Brooks <james@cachethq.io>
* (c) Joseph Cohen <joseph.cohen@dinkbit.com>
2015-05-23 14:48:33 +01:00
* (c) Graham Campbell <graham@cachethq.io>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace CachetHQ\Cachet\Http\Controllers\Api;
2014-11-26 16:08:47 +00:00
2014-12-20 21:20:17 +00:00
use CachetHQ\Cachet\Repositories\Metric\MetricRepository;
2015-01-02 12:05:50 +00:00
use GrahamCampbell\Binput\Facades\Binput;
2015-03-20 18:30:45 -06:00
use Illuminate\Http\Request;
2015-03-20 18:30:45 -06:00
class MetricController extends AbstractApiController
2014-12-20 21:20:17 +00:00
{
2015-01-01 20:13:53 +00:00
/**
* The metric repository instance.
*
* @var \CachetHQ\Cachet\Repositories\Metric\MetricRepository
*/
protected $metric;
2015-01-01 20:13:53 +00:00
/**
* Create a new metric controller instance.
*
* @param \CachetHQ\Cachet\Repositories\Metric\MetricRepository $metric
*/
2014-12-20 21:20:17 +00:00
public function __construct(MetricRepository $metric)
{
$this->metric = $metric;
}
2015-03-11 14:33:19 +00:00
/**
2014-12-30 18:19:22 +00:00
* Get all metrics.
*
* @return \Illuminate\Database\Eloquent\Collection
*/
2015-03-20 18:30:45 -06:00
public function getMetrics(Request $request)
2014-12-20 21:20:17 +00:00
{
2015-03-20 18:30:45 -06:00
$metrics = $this->metric->paginate(Binput::get('per_page', 20));
return $this->paginator($metrics, $request);
}
2014-11-26 16:08:47 +00:00
/**
2014-12-30 18:19:22 +00:00
* Get a single metric.
*
* @param int $id
*
* @return \CachetHQ\Cachet\Models\Metric
*/
2014-12-20 21:20:17 +00:00
public function getMetric($id)
{
2015-05-16 13:57:32 -05:00
return $this->item($this->metric->findOrFail($id));
}
2014-11-26 16:08:47 +00:00
2015-03-11 14:33:19 +00:00
/**
* Get all metric points.
*
* @param int $id
*
* @return \Illuminate\Database\Eloquent\Collection
*/
public function getMetricPoints($id)
{
2015-05-16 13:57:32 -05:00
return $this->collection($this->metric->points($id));
2015-03-11 14:33:19 +00:00
}
/**
2014-12-30 18:19:22 +00:00
* Create a new metric.
*
* @return \CachetHQ\Cachet\Models\Metric
*/
2014-12-20 21:20:17 +00:00
public function postMetrics()
{
return $this->item($this->metric->create(Binput::all()));
}
2014-11-26 16:08:47 +00:00
/**
2014-12-30 18:19:22 +00:00
* Update an existing metric.
*
* @param int $id
*
* @return \CachetHQ\Cachet\Models\Metric
*/
2014-12-20 21:20:17 +00:00
public function putMetric($id)
{
return $this->item($this->metric->update($id, Binput::all()));
}
2015-01-14 01:50:58 -06:00
/**
* Delete an existing metric.
*
* @param int $id
*
* @return \Dingo\Api\Http\Response
*/
public function deleteMetric($id)
{
$this->metric->destroy($id);
2015-03-20 18:30:45 -06:00
return $this->noContent();
2015-01-14 01:50:58 -06:00
}
}