Remove repositories from the API and switch cipher to rijndael-256
This commit is contained in:
committed by
James Brooks
parent
d788691006
commit
106c1a034a
@@ -11,39 +11,26 @@
|
||||
|
||||
namespace CachetHQ\Cachet\Http\Controllers\Api;
|
||||
|
||||
use CachetHQ\Cachet\Models\Component;
|
||||
use CachetHQ\Cachet\Models\Tag;
|
||||
use CachetHQ\Cachet\Repositories\Component\ComponentRepository;
|
||||
use Exception;
|
||||
use GrahamCampbell\Binput\Facades\Binput;
|
||||
use Illuminate\Contracts\Auth\Guard;
|
||||
use Illuminate\Http\Request;
|
||||
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
|
||||
|
||||
class ComponentController extends AbstractApiController
|
||||
{
|
||||
/**
|
||||
* The component repository instance.
|
||||
*
|
||||
* @var \CachetHQ\Cachet\Repositories\Component\ComponentRepository
|
||||
*/
|
||||
protected $component;
|
||||
|
||||
/**
|
||||
* Create a new component controller instance.
|
||||
*
|
||||
* @param \CachetHQ\Cachet\Repositories\Component\ComponentRepository $component
|
||||
*/
|
||||
public function __construct(ComponentRepository $component)
|
||||
{
|
||||
$this->component = $component;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all components.
|
||||
*
|
||||
* @param \Symfony\Component\HttpFoundation\Request $request
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Collection
|
||||
*/
|
||||
public function getComponents(Request $request)
|
||||
{
|
||||
$components = $this->component->paginate(Binput::get('per_page', 20));
|
||||
$components = Component::paginate(Binput::get('per_page', 20));
|
||||
|
||||
return $this->paginator($components, $request);
|
||||
}
|
||||
@@ -51,13 +38,13 @@ class ComponentController extends AbstractApiController
|
||||
/**
|
||||
* Get a single component.
|
||||
*
|
||||
* @param int $id
|
||||
* @param \CachetHQ\Cachet\Models\Component $component
|
||||
*
|
||||
* @return \CachetHQ\Cachet\Models\Component
|
||||
*/
|
||||
public function getComponent($id)
|
||||
public function getComponent(Component $component)
|
||||
{
|
||||
return $this->item($this->component->findOrFail($id));
|
||||
return $this->item($component);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -69,10 +56,18 @@ class ComponentController extends AbstractApiController
|
||||
*/
|
||||
public function postComponents(Guard $auth)
|
||||
{
|
||||
$component = $this->component->create(
|
||||
$auth->user()->id,
|
||||
Binput::except('tags')
|
||||
);
|
||||
$componentData = Binput::except('tags');
|
||||
$componentData['user_id'] = $auth->user()->id;
|
||||
|
||||
try {
|
||||
$component = Component::create($componentData);
|
||||
} catch (Exception $e) {
|
||||
throw new BadRequestHttpException();
|
||||
}
|
||||
|
||||
if (!$component->isValid()) {
|
||||
throw new BadRequestHttpException();
|
||||
}
|
||||
|
||||
if (Binput::has('tags')) {
|
||||
// The component was added successfully, so now let's deal with the tags.
|
||||
@@ -94,13 +89,17 @@ class ComponentController extends AbstractApiController
|
||||
/**
|
||||
* Update an existing component.
|
||||
*
|
||||
* @param int $id
|
||||
* @param \CachetHQ\Cachet\Models\Componet $component
|
||||
*
|
||||
* @return \CachetHQ\Cachet\Models\Component
|
||||
*/
|
||||
public function putComponent($id)
|
||||
public function putComponent(Component $component)
|
||||
{
|
||||
$component = $this->component->update($id, Binput::except('tags'));
|
||||
$component->update(Binput::except('tags'));
|
||||
|
||||
if (!$component->isValid('updating')) {
|
||||
throw new BadRequestHttpException();
|
||||
}
|
||||
|
||||
if (Binput::has('tags')) {
|
||||
$tags = preg_split('/ ?, ?/', Binput::get('tags'));
|
||||
@@ -121,13 +120,13 @@ class ComponentController extends AbstractApiController
|
||||
/**
|
||||
* Delete an existing component.
|
||||
*
|
||||
* @param int $id
|
||||
* @param \CachetHQ\Cachet\Models\Component $component
|
||||
*
|
||||
* @return \Dingo\Api\Http\Response
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function deleteComponent($id)
|
||||
public function deleteComponent(Component $component)
|
||||
{
|
||||
$this->component->destroy($id);
|
||||
$component->delete();
|
||||
|
||||
return $this->noContent();
|
||||
}
|
||||
|
||||
@@ -11,38 +11,26 @@
|
||||
|
||||
namespace CachetHQ\Cachet\Http\Controllers\Api;
|
||||
|
||||
use CachetHQ\Cachet\Repositories\Incident\IncidentRepository;
|
||||
use CachetHQ\Cachet\Models\Incident;
|
||||
use Exception;
|
||||
use GrahamCampbell\Binput\Facades\Binput;
|
||||
use Illuminate\Contracts\Auth\Guard;
|
||||
use Illuminate\Http\Request;
|
||||
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
|
||||
|
||||
class IncidentController extends AbstractApiController
|
||||
{
|
||||
/**
|
||||
* The incident repository instance.
|
||||
*
|
||||
* @var \CachetHQ\Cachet\Repositories\Incident\IncidentRepository
|
||||
*/
|
||||
protected $incident;
|
||||
|
||||
/**
|
||||
* Create a new incident controller instance.
|
||||
*
|
||||
* @param \CachetHQ\Cachet\Repositories\Incident\IncidentRepository $incident
|
||||
*/
|
||||
public function __construct(IncidentRepository $incident)
|
||||
{
|
||||
$this->incident = $incident;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all incidents.
|
||||
*
|
||||
* @param \Symfony\Component\HttpFoundation\Request $request
|
||||
* @param \CachetHQ\Cachet\Models\Incident $incident
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Collection
|
||||
*/
|
||||
public function getIncidents(Request $request)
|
||||
{
|
||||
$incidents = $this->incident->paginate(Binput::get('per_page', 20));
|
||||
$incidents = Incident::paginate(Binput::get('per_page', 20));
|
||||
|
||||
return $this->paginator($incidents, $request);
|
||||
}
|
||||
@@ -50,13 +38,13 @@ class IncidentController extends AbstractApiController
|
||||
/**
|
||||
* Get a single incident.
|
||||
*
|
||||
* @param int $id
|
||||
* @param \CachetHQ\Cachet\Models\Incident $incident
|
||||
*
|
||||
* @return \CachetHQ\Cachet\Models\Incident
|
||||
*/
|
||||
public function getIncident($id)
|
||||
public function getIncident(Incident $incident)
|
||||
{
|
||||
return $this->item($this->incident->findOrFail($id));
|
||||
return $this->item($incident);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -68,31 +56,50 @@ class IncidentController extends AbstractApiController
|
||||
*/
|
||||
public function postIncidents(Guard $auth)
|
||||
{
|
||||
return $this->item($this->incident->create($auth->user()->id, Binput::all()));
|
||||
$incidentData = Binput::all();
|
||||
$incidentData['user_id'] = $auth->user()->id;
|
||||
|
||||
try {
|
||||
$incident = Incident::create($incidentData);
|
||||
} catch (Exception $e) {
|
||||
throw new BadRequestHttpException();
|
||||
}
|
||||
|
||||
if ($incident->isValid()) {
|
||||
return $this->item($incident);
|
||||
}
|
||||
|
||||
throw new BadRequestHttpException();
|
||||
}
|
||||
|
||||
/**
|
||||
* Update an existing incident.
|
||||
*
|
||||
* @param int $id
|
||||
* @param \CachetHQ\Cachet\Models\Inicdent $incident
|
||||
*
|
||||
* @return \CachetHQ\Cachet\Models\Incident
|
||||
*/
|
||||
public function putIncident($id)
|
||||
public function putIncident(Incident $incident)
|
||||
{
|
||||
return $this->item($this->incident->update($id, Binput::all()));
|
||||
$incident->update(Binput::all());
|
||||
|
||||
if ($incident->isValid('updating')) {
|
||||
return $this->item($incident);
|
||||
}
|
||||
|
||||
throw new BadRequestHttpException();
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete an existing incident.
|
||||
*
|
||||
* @param int $id
|
||||
* @param \CachetHQ\Cachet\Models\Inicdent $incident
|
||||
*
|
||||
* @return \Dingo\Api\Http\Response
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function deleteIncident($id)
|
||||
public function deleteIncident(Incident $incident)
|
||||
{
|
||||
$this->incident->destroy($id);
|
||||
$incident->delete();
|
||||
|
||||
return $this->noContent();
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
@@ -11,63 +11,57 @@
|
||||
|
||||
namespace CachetHQ\Cachet\Http\Controllers\Api;
|
||||
|
||||
use CachetHQ\Cachet\Repositories\MetricPoint\MetricPointRepository;
|
||||
use CachetHQ\Cachet\Models\Metric;
|
||||
use CachetHQ\Cachet\Models\MetricPoint;
|
||||
use Exception;
|
||||
use GrahamCampbell\Binput\Facades\Binput;
|
||||
|
||||
class MetricPointController extends AbstractApiController
|
||||
{
|
||||
/**
|
||||
* The metric point repository instance.
|
||||
*
|
||||
* @var \CachetHQ\Cachet\Repositories\MetricPoint\MetricPointRepository
|
||||
*/
|
||||
protected $metricPoint;
|
||||
|
||||
/**
|
||||
* Create a new metric point controller instance.
|
||||
*
|
||||
* @param \CachetHQ\Cachet\Repositories\MetricPoint\MetricPointRepository $metricPoint
|
||||
*/
|
||||
public function __construct(MetricPointRepository $metricPoint)
|
||||
{
|
||||
$this->metricPoint = $metricPoint;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a single metric point.
|
||||
*
|
||||
* @param int $id
|
||||
* @param \CachetHQ\Cachet\Models\Metric $metric
|
||||
* @param \CachetHQ\Cachet\Models\MetricPoint $metricPoint
|
||||
*
|
||||
* @return \CachetHQ\Cachet\Models\MetricPoint
|
||||
*/
|
||||
public function getMetricPoints($id)
|
||||
public function getMetricPoints(Metric $metric, MetricPoint $metricPoint)
|
||||
{
|
||||
return $this->item($this->metricPoint->findOrFail($id));
|
||||
return $this->item($metricPoint);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new metric point.
|
||||
*
|
||||
* @param int $id
|
||||
* @param \CachetHQ\Cachet\Models\Metric $metric
|
||||
*
|
||||
* @return \CachetHQ\Cachet\Models\MetricPoint
|
||||
*/
|
||||
public function postMetricPoints($id)
|
||||
public function postMetricPoints(Metric $metric)
|
||||
{
|
||||
return $this->item($this->metricPoint->create($id, Binput::all()));
|
||||
$metricPointData = Binput::all();
|
||||
$metricPointData['metric_id'] = $metric->id;
|
||||
|
||||
try {
|
||||
$metricPoint = MetricPoint::create($metricPointData);
|
||||
} catch (Exception $e) {
|
||||
throw new BadRequestHttpException();
|
||||
}
|
||||
|
||||
return $this->item($metricPoint);
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates a metric point.
|
||||
*
|
||||
* @param int $metricId
|
||||
* @param int $pointId
|
||||
* @param \CachetHQ\Cachet\Models\Metric $metric
|
||||
* @param \CachetHQ\Cachet\Models\MetircPoint $metricPoint
|
||||
*
|
||||
* @return \CachetHQ\Cachet\Models\MetricPoint
|
||||
*/
|
||||
public function putMetricPoint($metricId, $pointId)
|
||||
public function putMetricPoint(Metric $metric, MetricPoint $metricPoint)
|
||||
{
|
||||
$metricPoint = $this->metricPoint->findOrFail($pointId);
|
||||
$metricPoint->update(Binput::all());
|
||||
|
||||
return $this->item($metricPoint);
|
||||
@@ -76,14 +70,14 @@ class MetricPointController extends AbstractApiController
|
||||
/**
|
||||
* Destroys a metric point.
|
||||
*
|
||||
* @param int $metricId
|
||||
* @param int $pointId
|
||||
* @param \CachetHQ\Cachet\Models\Metric $metric
|
||||
* @param \CachetHQ\Cachet\Models\MetricPoint $metricPoint
|
||||
*
|
||||
* @return \Dingo\Api\Http\Response
|
||||
*/
|
||||
public function deleteMetricPoint($metricId, $pointId)
|
||||
public function deleteMetricPoint(Metric $metric, MetricPoint $metricPoint)
|
||||
{
|
||||
$this->metricPoint->destroy($pointId);
|
||||
$metricPoint->delete();
|
||||
|
||||
return $this->noContent();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user