2014-11-26 23:20:31 +00:00
|
|
|
<?php
|
2014-11-26 16:08:47 +00:00
|
|
|
|
2015-04-19 08:52:39 +01:00
|
|
|
/*
|
|
|
|
* This file is part of Cachet.
|
|
|
|
*
|
|
|
|
* (c) James Brooks <james@cachethq.io>
|
2015-05-19 10:45:38 +01:00
|
|
|
* (c) Joseph Cohen <joseph.cohen@dinkbit.com>
|
2015-05-23 14:48:33 +01:00
|
|
|
* (c) Graham Campbell <graham@cachethq.io>
|
2015-04-19 08:52:39 +01:00
|
|
|
*
|
|
|
|
* For the full copyright and license information, please view the LICENSE
|
|
|
|
* file that was distributed with this source code.
|
|
|
|
*/
|
|
|
|
|
2015-01-02 00:18:19 +00:00
|
|
|
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;
|
2014-11-26 23:20:31 +00:00
|
|
|
|
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
|
|
|
|
*/
|
2014-12-01 12:03:32 +00:00
|
|
|
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)
|
|
|
|
{
|
2014-12-01 12:03:32 +00:00
|
|
|
$this->metric = $metric;
|
|
|
|
}
|
2015-03-11 14:33:19 +00:00
|
|
|
|
2014-11-27 16:36:24 +00:00
|
|
|
/**
|
2014-12-30 18:19:22 +00:00
|
|
|
* Get all metrics.
|
2014-11-27 16:36:24 +00:00
|
|
|
*
|
|
|
|
* @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-27 16:36:24 +00:00
|
|
|
}
|
2014-11-26 16:08:47 +00:00
|
|
|
|
2014-11-27 16:36:24 +00:00
|
|
|
/**
|
2014-12-30 18:19:22 +00:00
|
|
|
* Get a single metric.
|
2014-11-27 16:36:24 +00:00
|
|
|
*
|
|
|
|
* @param int $id
|
|
|
|
*
|
2015-01-02 00:18:19 +00:00
|
|
|
* @return \CachetHQ\Cachet\Models\Metric
|
2014-11-27 16:36:24 +00:00
|
|
|
*/
|
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-27 16:36:24 +00:00
|
|
|
}
|
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-11-27 16:36:24 +00:00
|
|
|
/**
|
2014-12-30 18:19:22 +00:00
|
|
|
* Create a new metric.
|
2014-11-27 16:36:24 +00:00
|
|
|
*
|
2015-01-02 00:18:19 +00:00
|
|
|
* @return \CachetHQ\Cachet\Models\Metric
|
2014-11-27 16:36:24 +00:00
|
|
|
*/
|
2014-12-20 21:20:17 +00:00
|
|
|
public function postMetrics()
|
|
|
|
{
|
2015-05-20 12:57:22 -05:00
|
|
|
return $this->item($this->metric->create(Binput::all()));
|
2014-11-27 16:36:24 +00:00
|
|
|
}
|
2014-11-26 16:08:47 +00:00
|
|
|
|
2014-11-27 16:36:24 +00:00
|
|
|
/**
|
2014-12-30 18:19:22 +00:00
|
|
|
* Update an existing metric.
|
2014-11-27 16:36:24 +00:00
|
|
|
*
|
|
|
|
* @param int $id
|
|
|
|
*
|
2015-01-02 00:18:19 +00:00
|
|
|
* @return \CachetHQ\Cachet\Models\Metric
|
2014-11-27 16:36:24 +00:00
|
|
|
*/
|
2014-12-20 21:20:17 +00:00
|
|
|
public function putMetric($id)
|
|
|
|
{
|
2015-05-20 12:57:22 -05:00
|
|
|
return $this->item($this->metric->update($id, Binput::all()));
|
2014-11-27 16:36:24 +00:00
|
|
|
}
|
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
|
|
|
}
|
2014-11-27 22:08:28 +00:00
|
|
|
}
|