Remove repositories from the API and switch cipher to rijndael-256

This commit is contained in:
James Brooks
2015-05-23 19:09:24 +01:00
committed by James Brooks
parent d788691006
commit 106c1a034a
24 changed files with 222 additions and 939 deletions

View File

@@ -11,37 +11,24 @@
namespace CachetHQ\Cachet\Http\Controllers\Api;
use CachetHQ\Cachet\Repositories\Metric\MetricRepository;
use CachetHQ\Cachet\Models\Metric;
use Exception;
use GrahamCampbell\Binput\Facades\Binput;
use Illuminate\Http\Request;
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
class MetricController extends AbstractApiController
{
/**
* The metric repository instance.
*
* @var \CachetHQ\Cachet\Repositories\Metric\MetricRepository
*/
protected $metric;
/**
* Create a new metric controller instance.
*
* @param \CachetHQ\Cachet\Repositories\Metric\MetricRepository $metric
*/
public function __construct(MetricRepository $metric)
{
$this->metric = $metric;
}
/**
* Get all metrics.
*
* @param \Symfony\Component\HttpFoundation\Request $request
*
* @return \Illuminate\Database\Eloquent\Collection
*/
public function getMetrics(Request $request)
{
$metrics = $this->metric->paginate(Binput::get('per_page', 20));
$metrics = Metric::paginate(Binput::get('per_page', 20));
return $this->paginator($metrics, $request);
}
@@ -49,25 +36,25 @@ class MetricController extends AbstractApiController
/**
* Get a single metric.
*
* @param int $id
* @param \CachetHQ\Cachet\Models\Metric $metric
*
* @return \CachetHQ\Cachet\Models\Metric
*/
public function getMetric($id)
public function getMetric(Metric $metric)
{
return $this->item($this->metric->findOrFail($id));
return $this->item($metric);
}
/**
* Get all metric points.
*
* @param int $id
* @param \CachetHQ\Cachet\Models\Metric $metric
*
* @return \Illuminate\Database\Eloquent\Collection
*/
public function getMetricPoints($id)
public function getMetricPoints(Metric $metric)
{
return $this->collection($this->metric->points($id));
return $this->collection($metric->points);
}
/**
@@ -77,31 +64,47 @@ class MetricController extends AbstractApiController
*/
public function postMetrics()
{
return $this->item($this->metric->create(Binput::all()));
try {
$metric = Metric::create(Binput::all());
} catch (Exception $e) {
throw new BadRequestHttpException();
}
if ($metric->isValid()) {
return $this->item($metric);
}
throw new BadRequestHttpException();
}
/**
* Update an existing metric.
*
* @param int $id
* @param \CachetHQ\Cachet\Models\Metric $metric
*
* @return \CachetHQ\Cachet\Models\Metric
*/
public function putMetric($id)
public function putMetric(Metric $metric)
{
return $this->item($this->metric->update($id, Binput::all()));
$metric->update(Binput::all());
if ($metric->isValid('updating')) {
return $this->item($metric);
}
throw new BadRequestHttpException();
}
/**
* Delete an existing metric.
*
* @param int $id
* @param \CachetHQ\Cachet\Models\Metric $metric
*
* @return \Dingo\Api\Http\Response
* @return \Illuminate\Http\JsonResponse
*/
public function deleteMetric($id)
public function deleteMetric(Metric $metric)
{
$this->metric->destroy($id);
$metric->delete();
return $this->noContent();
}