Namespaced models and refactored filters

This commit is contained in:
Graham Campbell
2015-01-02 00:18:19 +00:00
parent 15a6694865
commit 0ccb5e289c
66 changed files with 310 additions and 195 deletions

View File

@@ -0,0 +1,76 @@
<?php
namespace CachetHQ\Cachet\Http\Controllers\Api;
use CachetHQ\Cachet\Repositories\Component\ComponentRepository;
use Dingo\Api\Routing\ControllerTrait;
use Illuminate\Routing\Controller;
use Illuminate\Support\Facades\Input;
class ComponentController extends Controller
{
use ControllerTrait;
/**
* 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
*
* @return void
*/
public function __construct(ComponentRepository $component)
{
$this->component = $component;
}
/**
* Get all components.
*
* @return \Illuminate\Database\Eloquent\Collection
*/
public function getComponents()
{
return $this->component->all();
}
/**
* Get a single component.
*
* @param int $id
*
* @return \CachetHQ\Cachet\Models\Component
*/
public function getComponent($id)
{
return $this->component->findOrFail($id);
}
/**
* Return a component with incidents.
*
* @param int $id
*
* @return \CachetHQ\Cachet\Models\Component
*/
public function getComponentIncidents($id)
{
return $this->component->with($id, ['incidents']);
}
/**
* Create a new component.
*
* @return \CachetHQ\Cachet\Models\Component
*/
public function postComponents()
{
return $this->component->create($this->auth->user()->id, Input::all());
}
}

View File

@@ -0,0 +1,76 @@
<?php
namespace CachetHQ\Cachet\Http\Controllers\Api;
use CachetHQ\Cachet\Repositories\Incident\IncidentRepository;
use Dingo\Api\Routing\ControllerTrait;
use Illuminate\Routing\Controller;
use Illuminate\Support\Facades\Input;
class IncidentController extends Controller
{
use ControllerTrait;
/**
* 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
*
* @return void
*/
public function __construct(IncidentRepository $incident)
{
$this->incident = $incident;
}
/**
* Get all incidents.
*
* @return \Illuminate\Database\Eloquent\Collection
*/
public function getIncidents()
{
return $this->incident->all();
}
/**
* Get a single incident.
*
* @param int $id
*
* @return \CachetHQ\Cachet\Models\Incident
*/
public function getIncident($id)
{
return $this->incident->findOrFail($id);
}
/**
* Create a new incident.
*
* @return \CachetHQ\Cachet\Models\Incident
*/
public function postIncidents()
{
return $this->incident->create($this->auth->user()->id, Input::all());
}
/**
* Update an existing incident.
*
* @param int $id
*
* @return \CachetHQ\Cachet\Models\Incident
*/
public function putIncident($id)
{
return $this->incident->update($id, Input::all());
}
}

View File

@@ -0,0 +1,75 @@
<?php
namespace CachetHQ\Cachet\Http\Controllers\Api;
use CachetHQ\Cachet\Repositories\Metric\MetricRepository;
use Dingo\Api\Routing\ControllerTrait;
use Illuminate\Routing\Controller;
use Illuminate\Support\Facades\Input;
class MetricController extends Controller
{
use ControllerTrait;
/**
* 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
*
* @return void
*/
public function __construct(MetricRepository $metric)
{
$this->metric = $metric;
}
/**
* Get all metrics.
*
* @return \Illuminate\Database\Eloquent\Collection
*/
public function getMetrics()
{
return $this->metric->all();
}
/**
* Get a single metric.
*
* @param int $id
*
* @return \CachetHQ\Cachet\Models\Metric
*/
public function getMetric($id)
{
return $this->metric->findOrFail($id);
}
/**
* Create a new metric.
*
* @return \CachetHQ\Cachet\Models\Metric
*/
public function postMetrics()
{
return $this->metric->create(Input::all());
}
/**
* Update an existing metric.
*
* @param int $id
*
* @return \CachetHQ\Cachet\Models\Metric
*/
public function putMetric($id)
{
return $this->metric->update($id, Input::all());
}
}

View File

@@ -0,0 +1,63 @@
<?php
namespace CachetHQ\Cachet\Http\Controllers\Api;
use CachetHQ\Cachet\Repositories\MetricPoint\MetricPointRepository;
use Dingo\Api\Routing\ControllerTrait;
use Illuminate\Routing\Controller;
use Illuminate\Support\Facades\Input;
class MetricPointController extends Controller
{
use ControllerTrait;
/**
* 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
*
* @return void
*/
public function __construct(MetricPointRepository $metricPoint)
{
$this->metricPoint = $metricPoint;
}
/**
* Get all metric points.
*
* @return \Illuminate\Database\Eloquent\Collection
*/
public function getMetricPoints()
{
return $this->metricPoint->all();
}
/**
* Get a single metric point.
*
* @param int $id
*
* @return \CachetHQ\Cachet\Models\MetricPoint
*/
public function getMetricPoint($id)
{
return $this->metricPoint->findOrFail($id);
}
/**
* Create a new metric point.
*
* @return \CachetHQ\Cachet\Models\MetricPoint
*/
public function postMetricPoints()
{
return $this->metricPoint->create(Input::all());
}
}