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();
|
||||
}
|
||||
|
||||
@@ -31,33 +31,33 @@ class ApiRoutes
|
||||
|
||||
// Components
|
||||
$router->get('components', 'ComponentController@getComponents');
|
||||
$router->get('components/{id}', 'ComponentController@getComponent');
|
||||
$router->get('components/{component}', 'ComponentController@getComponent');
|
||||
|
||||
// Incidents
|
||||
$router->get('incidents', 'IncidentController@getIncidents');
|
||||
$router->get('incidents/{id}', 'IncidentController@getIncident');
|
||||
$router->get('incidents/{incident}', 'IncidentController@getIncident');
|
||||
|
||||
// Metrics
|
||||
$router->get('metrics', 'MetricController@getMetrics');
|
||||
$router->get('metrics/{id}', 'MetricController@getMetric');
|
||||
$router->get('metrics/{id}/points', 'MetricController@getMetricPoints');
|
||||
$router->get('metrics/{metric}', 'MetricController@getMetric');
|
||||
$router->get('metrics/{metric}/points', 'MetricController@getMetricPoints');
|
||||
|
||||
// Api protected
|
||||
$router->group(['middleware' => 'auth.api'], function ($router) {
|
||||
$router->post('components', 'ComponentController@postComponents');
|
||||
$router->post('incidents', 'IncidentController@postIncidents');
|
||||
$router->post('metrics', 'MetricController@postMetrics');
|
||||
$router->post('metrics/{id}/points', 'MetricPointController@postMetricPoints');
|
||||
$router->post('metrics/{metric}/points', 'MetricPointController@postMetricPoints');
|
||||
|
||||
$router->put('components/{id}', 'ComponentController@putComponent');
|
||||
$router->put('incidents/{id}', 'IncidentController@putIncident');
|
||||
$router->put('metrics/{id}', 'MetricController@putMetric');
|
||||
$router->put('metrics/{id}/points/{metric_id}', 'MetricPointController@putMetricPoint');
|
||||
$router->put('components/{component}', 'ComponentController@putComponent');
|
||||
$router->put('incidents/{incident}', 'IncidentController@putIncident');
|
||||
$router->put('metrics/{metric}', 'MetricController@putMetric');
|
||||
$router->put('metrics/{metric}/points/{metric_point}', 'MetricPointController@putMetricPoint');
|
||||
|
||||
$router->delete('components/{id}', 'ComponentController@deleteComponent');
|
||||
$router->delete('incidents/{id}', 'IncidentController@deleteIncident');
|
||||
$router->delete('metrics/{id}', 'MetricController@deleteMetric');
|
||||
$router->delete('metrics/{id}/points/{metric_id}', 'MetricPointController@deleteMetricPoint');
|
||||
$router->delete('components/{component}', 'ComponentController@deleteComponent');
|
||||
$router->delete('incidents/{incident}', 'IncidentController@deleteIncident');
|
||||
$router->delete('metrics/{metric}', 'MetricController@deleteMetric');
|
||||
$router->delete('metrics/{metric}/points/{metric_point}', 'MetricPointController@deleteMetricPoint');
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@@ -41,7 +41,7 @@ class Component extends Model implements HasPresenter
|
||||
*/
|
||||
protected $rules = [
|
||||
'user_id' => 'integer|required',
|
||||
'name' => 'required',
|
||||
'name' => 'required|string',
|
||||
'status' => 'integer|required',
|
||||
'link' => 'url',
|
||||
];
|
||||
|
||||
@@ -1,65 +0,0 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Cachet.
|
||||
*
|
||||
* (c) Cachet HQ <support@cachethq.io>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace CachetHQ\Cachet\Repositories\Component;
|
||||
|
||||
interface ComponentRepository
|
||||
{
|
||||
/**
|
||||
* Returns all models.
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Collection
|
||||
*/
|
||||
public function all();
|
||||
|
||||
/**
|
||||
* Create a new model.
|
||||
*
|
||||
* @param int $userId
|
||||
* @param array $data
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Model
|
||||
*/
|
||||
public function create($userId, array $data);
|
||||
|
||||
/**
|
||||
* Update a model by id.
|
||||
*
|
||||
* @param int $id
|
||||
* @param array $data
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Model
|
||||
*/
|
||||
public function update($id, array $data);
|
||||
|
||||
/**
|
||||
* Finds a model by id.
|
||||
*
|
||||
* @param int $id
|
||||
*
|
||||
* @throws \Illuminate\Database\Eloquent\ModelNotFoundException
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Model
|
||||
*/
|
||||
public function findOrFail($id);
|
||||
|
||||
/**
|
||||
* Returns an object with related relationships.
|
||||
*
|
||||
* @param int $id
|
||||
* @param string[] $with
|
||||
*
|
||||
* @throws \Illuminate\Database\Eloquent\ModelNotFoundException
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Model
|
||||
*/
|
||||
public function with($id, array $with = []);
|
||||
}
|
||||
@@ -1,74 +0,0 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Cachet.
|
||||
*
|
||||
* (c) Cachet HQ <support@cachethq.io>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace CachetHQ\Cachet\Repositories\Component;
|
||||
|
||||
use CachetHQ\Cachet\Models\Component;
|
||||
use CachetHQ\Cachet\Repositories\EloquentRepository;
|
||||
|
||||
class EloquentComponentRepository extends EloquentRepository implements ComponentRepository
|
||||
{
|
||||
/**
|
||||
* The eloquent model instance.
|
||||
*
|
||||
* @var \CachetHQ\Cachet\Models\Component
|
||||
*/
|
||||
protected $model;
|
||||
|
||||
/**
|
||||
* Create a new eloquent component repository instance.
|
||||
*
|
||||
* @param \CachetHQ\Cachet\Models\Component $model
|
||||
*/
|
||||
public function __construct(Component $model)
|
||||
{
|
||||
$this->model = $model;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new model.
|
||||
*
|
||||
* @param int $userId
|
||||
* @param array $data
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Model
|
||||
*/
|
||||
public function create($userId, array $data)
|
||||
{
|
||||
$component = new $this->model($data);
|
||||
$component->user_id = $userId;
|
||||
|
||||
$this->validate($component);
|
||||
|
||||
$component->saveOrFail();
|
||||
|
||||
return $component;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update a model by id.
|
||||
*
|
||||
* @param int $id
|
||||
* @param array $data
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Model
|
||||
*/
|
||||
public function update($id, array $data)
|
||||
{
|
||||
$component = $this->model->findOrFail($id);
|
||||
$component->fill($data);
|
||||
$this->validate($component);
|
||||
|
||||
$component->update($data);
|
||||
|
||||
return $component;
|
||||
}
|
||||
}
|
||||
@@ -1,182 +0,0 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Cachet.
|
||||
*
|
||||
* (c) Cachet HQ <support@cachethq.io>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace CachetHQ\Cachet\Repositories;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\ModelNotFoundException;
|
||||
|
||||
abstract class EloquentRepository
|
||||
{
|
||||
/**
|
||||
* Returns all models.
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Collection
|
||||
*/
|
||||
public function all()
|
||||
{
|
||||
return $this->model->all();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns paginated result.
|
||||
*
|
||||
* @param int $perPage
|
||||
*
|
||||
* @return \Illuminate\Pagination\Paginator
|
||||
*/
|
||||
public function paginate($perPage = 20)
|
||||
{
|
||||
return $this->model->paginate($perPage);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an object with related relationships.
|
||||
*
|
||||
* @param int $id
|
||||
* @param string[] $with
|
||||
*
|
||||
* @throws \Illuminate\Database\Eloquent\ModelNotFoundException
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Model
|
||||
*/
|
||||
public function with($id, array $with = [])
|
||||
{
|
||||
return $this->model->with($with)->findOrFail($id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the model to query against a user id.
|
||||
*
|
||||
* @param int $id
|
||||
* @param string $column
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function withAuth($id, $column = 'user_id')
|
||||
{
|
||||
$this->model = $this->model->where($column, $id);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds a model by ID.
|
||||
*
|
||||
* @param int $id
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Model
|
||||
*/
|
||||
public function find($id)
|
||||
{
|
||||
return $this->model->find($id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds a model by id.
|
||||
*
|
||||
* @param int $id
|
||||
*
|
||||
* @throws \Illuminate\Database\Eloquent\ModelNotFoundException
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Model
|
||||
*/
|
||||
public function findOrFail($id)
|
||||
{
|
||||
return $this->model->findOrFail($id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds a model by type.
|
||||
*
|
||||
* @param string $key
|
||||
* @param string $value
|
||||
* @param array $columns
|
||||
*
|
||||
* @throws \Illuminate\Database\Eloquent\ModelNotFoundException
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Model
|
||||
*/
|
||||
public function findByOrFail($key, $value, $columns = ['*'])
|
||||
{
|
||||
$model = $this->model->where($key, $value)->first($columns);
|
||||
|
||||
if ($model === null) {
|
||||
throw new ModelNotFoundException();
|
||||
}
|
||||
|
||||
return $model;
|
||||
}
|
||||
|
||||
/**
|
||||
* Counts the number of rows returned.
|
||||
*
|
||||
* @param string|null $key
|
||||
* @param string|null $value
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function count($key = null, $value = null)
|
||||
{
|
||||
if ($key === null || $value === null) {
|
||||
return $this->model->count();
|
||||
}
|
||||
|
||||
return $this->model->where($key, $value)->count();
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes a model by id.
|
||||
*
|
||||
* @param int $id
|
||||
*/
|
||||
public function destroy($id)
|
||||
{
|
||||
$this->model->destroy($id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate a given model with Watson validation.
|
||||
*
|
||||
* @param \Illuminate\Database\Eloquent\Model $model
|
||||
*
|
||||
* @throws \CachetHQ\Cachet\Repositories\InvalidModelValidationException
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function validate(Model $model)
|
||||
{
|
||||
if ($model->isInvalid()) {
|
||||
throw new InvalidModelValidationException('Validation failed on the model.');
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate whether a model has a correct relationship.
|
||||
*
|
||||
* @param \Illuminate\Database\Eloquent\Model $model
|
||||
* @param string $relationship
|
||||
*
|
||||
* @throws \CachetHQ\Cachet\Repositories\InvalidRelationshipException
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function hasRelationship(Model $model, $relationship)
|
||||
{
|
||||
if ($model->$relationship === null) {
|
||||
throw new InvalidRelationshipException('The relationship was not valid.');
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
@@ -1,81 +0,0 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Cachet.
|
||||
*
|
||||
* (c) Cachet HQ <support@cachethq.io>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace CachetHQ\Cachet\Repositories\Incident;
|
||||
|
||||
use CachetHQ\Cachet\Models\Incident;
|
||||
use CachetHQ\Cachet\Repositories\EloquentRepository;
|
||||
|
||||
class EloquentIncidentRepository extends EloquentRepository implements IncidentRepository
|
||||
{
|
||||
/**
|
||||
* The eloquent model instance.
|
||||
*
|
||||
* @var \CachetHQ\Cachet\Models\Incident
|
||||
*/
|
||||
protected $model;
|
||||
|
||||
/**
|
||||
* Create a new eloquent incident repository instance.
|
||||
*
|
||||
* @param \CachetHQ\Cachet\Models\Incident $model
|
||||
*/
|
||||
public function __construct(Incident $model)
|
||||
{
|
||||
$this->model = $model;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new model.
|
||||
*
|
||||
* @param int $userId
|
||||
* @param array $data
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Model
|
||||
*/
|
||||
public function create($userId, array $data)
|
||||
{
|
||||
$incident = new $this->model($data);
|
||||
$incident->user_id = $userId;
|
||||
$this->validate($incident);
|
||||
|
||||
if (isset($data['component_id'])) {
|
||||
$this->hasRelationship($incident, 'component');
|
||||
}
|
||||
|
||||
$incident->saveOrFail();
|
||||
|
||||
return $incident;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update a model by id.
|
||||
*
|
||||
* @param int $id
|
||||
* @param array $data
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Model
|
||||
*/
|
||||
public function update($id, array $data)
|
||||
{
|
||||
$incident = $this->model->findOrFail($id);
|
||||
$incident->fill($data);
|
||||
$this->validate($incident);
|
||||
|
||||
if (isset($data['component_id'])) {
|
||||
$this->hasRelationship($incident, 'component');
|
||||
}
|
||||
|
||||
$incident->update($data);
|
||||
|
||||
return $incident;
|
||||
}
|
||||
}
|
||||
@@ -1,62 +0,0 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Cachet.
|
||||
*
|
||||
* (c) Cachet HQ <support@cachethq.io>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace CachetHQ\Cachet\Repositories\Incident;
|
||||
|
||||
interface IncidentRepository
|
||||
{
|
||||
/**
|
||||
* Returns all models.
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Collection
|
||||
*/
|
||||
public function all();
|
||||
|
||||
/**
|
||||
* Returns paginated result.
|
||||
*
|
||||
* @param int $perPage
|
||||
*
|
||||
* @return \Illuminate\Pagination\Paginator
|
||||
*/
|
||||
public function paginate($perPage = 20);
|
||||
|
||||
/**
|
||||
* Create a new model.
|
||||
*
|
||||
* @param int $userId
|
||||
* @param array $data
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Model
|
||||
*/
|
||||
public function create($userId, array $data);
|
||||
|
||||
/**
|
||||
* Finds a model by id.
|
||||
*
|
||||
* @param int $id
|
||||
*
|
||||
* @throws \Illuminate\Database\Eloquent\ModelNotFoundException
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Model
|
||||
*/
|
||||
public function findOrFail($id);
|
||||
|
||||
/**
|
||||
* Update a model by id.
|
||||
*
|
||||
* @param int $id
|
||||
* @param array $data
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Model
|
||||
*/
|
||||
public function update($id, array $data);
|
||||
}
|
||||
@@ -1,19 +0,0 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Cachet.
|
||||
*
|
||||
* (c) Cachet HQ <support@cachethq.io>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace CachetHQ\Cachet\Repositories;
|
||||
|
||||
use Exception;
|
||||
|
||||
class InvalidModelValidationException extends Exception
|
||||
{
|
||||
//
|
||||
}
|
||||
@@ -1,19 +0,0 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Cachet.
|
||||
*
|
||||
* (c) Cachet HQ <support@cachethq.io>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace CachetHQ\Cachet\Repositories;
|
||||
|
||||
use Exception;
|
||||
|
||||
class InvalidRelationshipException extends Exception
|
||||
{
|
||||
//
|
||||
}
|
||||
@@ -1,87 +0,0 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Cachet.
|
||||
*
|
||||
* (c) Cachet HQ <support@cachethq.io>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace CachetHQ\Cachet\Repositories\Metric;
|
||||
|
||||
use CachetHQ\Cachet\Models\Metric;
|
||||
use CachetHQ\Cachet\Repositories\EloquentRepository;
|
||||
|
||||
class EloquentMetricRepository extends EloquentRepository implements MetricRepository
|
||||
{
|
||||
/**
|
||||
* The eloquent model instance.
|
||||
*
|
||||
* @var \CachetHQ\Cachet\Models\Metric
|
||||
*/
|
||||
protected $model;
|
||||
|
||||
/**
|
||||
* Create a new eloquent metric repository instance.
|
||||
*
|
||||
* @param \CachetHQ\Cachet\Models\Metric $model
|
||||
*/
|
||||
public function __construct(Metric $model)
|
||||
{
|
||||
$this->model = $model;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new model.
|
||||
*
|
||||
* @param array $data
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Model
|
||||
*/
|
||||
public function create(array $data)
|
||||
{
|
||||
$metric = new $this->model($data);
|
||||
|
||||
$this->validate($metric);
|
||||
|
||||
$metric->saveOrFail();
|
||||
|
||||
return $metric;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update a model by id.
|
||||
*
|
||||
* @param int $id
|
||||
* @param array $data
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Model
|
||||
*/
|
||||
public function update($id, array $data)
|
||||
{
|
||||
$metric = $this->model->findOrFail($id);
|
||||
$metric->fill($data);
|
||||
|
||||
$this->validate($metric);
|
||||
|
||||
$metric->update($data);
|
||||
|
||||
return $metric;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all metric point models.
|
||||
*
|
||||
* @param int $id
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Collection
|
||||
*/
|
||||
public function points($id)
|
||||
{
|
||||
$metric = $this->model->findOrFail($id);
|
||||
|
||||
return $metric->points;
|
||||
}
|
||||
}
|
||||
@@ -1,61 +0,0 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Cachet.
|
||||
*
|
||||
* (c) Cachet HQ <support@cachethq.io>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace CachetHQ\Cachet\Repositories\Metric;
|
||||
|
||||
interface MetricRepository
|
||||
{
|
||||
/**
|
||||
* Returns all models.
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Collection
|
||||
*/
|
||||
public function all();
|
||||
|
||||
/**
|
||||
* Returns all metric point models.
|
||||
*
|
||||
* @param int $id
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Collection
|
||||
*/
|
||||
public function points($id);
|
||||
|
||||
/**
|
||||
* Create a new model.
|
||||
*
|
||||
* @param array $data
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Model
|
||||
*/
|
||||
public function create(array $data);
|
||||
|
||||
/**
|
||||
* Finds a model by id.
|
||||
*
|
||||
* @param int $id
|
||||
*
|
||||
* @throws \Illuminate\Database\Eloquent\ModelNotFoundException
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Model
|
||||
*/
|
||||
public function findOrFail($id);
|
||||
|
||||
/**
|
||||
* Update a model by id.
|
||||
*
|
||||
* @param int $id
|
||||
* @param array $data
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Model
|
||||
*/
|
||||
public function update($id, array $data);
|
||||
}
|
||||
@@ -1,75 +0,0 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Cachet.
|
||||
*
|
||||
* (c) Cachet HQ <support@cachethq.io>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace CachetHQ\Cachet\Repositories\MetricPoint;
|
||||
|
||||
use CachetHQ\Cachet\Models\MetricPoint;
|
||||
use CachetHQ\Cachet\Repositories\EloquentRepository;
|
||||
|
||||
class EloquentMetricPointRepository extends EloquentRepository implements MetricPointRepository
|
||||
{
|
||||
/**
|
||||
* The eloquent model instance.
|
||||
*
|
||||
* @var \CachetHQ\Cachet\Models\MetricPoint
|
||||
*/
|
||||
protected $model;
|
||||
|
||||
/**
|
||||
* Create a new eloquent metric point repository instance.
|
||||
*
|
||||
* @param \CachetHQ\Cachet\Models\MetricPoint $model
|
||||
*/
|
||||
public function __construct(MetricPoint $model)
|
||||
{
|
||||
$this->model = $model;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new model.
|
||||
*
|
||||
* @param int $id
|
||||
* @param array $data
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Model
|
||||
*/
|
||||
public function create($id, array $data)
|
||||
{
|
||||
$data['metric_id'] = $id;
|
||||
$metric = new $this->model($data);
|
||||
|
||||
$this->validate($metric);
|
||||
|
||||
$metric->saveOrFail();
|
||||
|
||||
return $metric;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update a model by id.
|
||||
*
|
||||
* @param int $id
|
||||
* @param array $data
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Model
|
||||
*/
|
||||
public function update($id, array $data)
|
||||
{
|
||||
$metric = $this->model->findOrFail($id);
|
||||
$metric->fill($data);
|
||||
|
||||
$this->validate($metric);
|
||||
|
||||
$metric->update($data);
|
||||
|
||||
return $metric;
|
||||
}
|
||||
}
|
||||
@@ -1,53 +0,0 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Cachet.
|
||||
*
|
||||
* (c) Cachet HQ <support@cachethq.io>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace CachetHQ\Cachet\Repositories\MetricPoint;
|
||||
|
||||
interface MetricPointRepository
|
||||
{
|
||||
/**
|
||||
* Returns all models.
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Collection
|
||||
*/
|
||||
public function all();
|
||||
|
||||
/**
|
||||
* Create a new model.
|
||||
*
|
||||
* @param int $id
|
||||
* @param array $data
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Model
|
||||
*/
|
||||
public function create($id, array $data);
|
||||
|
||||
/**
|
||||
* Finds a model by id.
|
||||
*
|
||||
* @param int $id
|
||||
*
|
||||
* @throws \Illuminate\Database\Eloquent\ModelNotFoundException
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Model
|
||||
*/
|
||||
public function findOrFail($id);
|
||||
|
||||
/**
|
||||
* Update a model by id.
|
||||
*
|
||||
* @param int $id
|
||||
* @param array $data
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Model
|
||||
*/
|
||||
public function update($id, array $data);
|
||||
}
|
||||
8
composer.lock
generated
8
composer.lock
generated
@@ -1567,12 +1567,12 @@
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/laravel/framework.git",
|
||||
"reference": "3f3307c911f2876447ce61d8c3aea33a99389441"
|
||||
"reference": "6a785aeeeff0739e67b79b015c337fe834133a48"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/laravel/framework/zipball/3f3307c911f2876447ce61d8c3aea33a99389441",
|
||||
"reference": "3f3307c911f2876447ce61d8c3aea33a99389441",
|
||||
"url": "https://api.github.com/repos/laravel/framework/zipball/6a785aeeeff0739e67b79b015c337fe834133a48",
|
||||
"reference": "6a785aeeeff0739e67b79b015c337fe834133a48",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
@@ -1687,7 +1687,7 @@
|
||||
"framework",
|
||||
"laravel"
|
||||
],
|
||||
"time": "2015-06-07 02:48:12"
|
||||
"time": "2015-06-07 20:48:54"
|
||||
},
|
||||
{
|
||||
"name": "league/commonmark",
|
||||
|
||||
@@ -89,7 +89,7 @@ return [
|
||||
|
||||
'key' => env('APP_KEY', 'SomeRandomString'),
|
||||
|
||||
'cipher' => 'AES-256-CBC',
|
||||
'cipher' => 'rijndael-256',
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
@@ -170,7 +170,6 @@ return [
|
||||
'CachetHQ\Cachet\Providers\ConfigServiceProvider',
|
||||
'CachetHQ\Cachet\Providers\ConsoleServiceProvider',
|
||||
'CachetHQ\Cachet\Providers\EventServiceProvider',
|
||||
'CachetHQ\Cachet\Providers\RepositoryServiceProvider',
|
||||
'CachetHQ\Cachet\Providers\RouteServiceProvider',
|
||||
'CachetHQ\Cachet\Providers\SegmentServiceProvider',
|
||||
'CachetHQ\Segment\SegmentServiceProvider',
|
||||
|
||||
21
public/build/dist/css/all-c8eb2347.css
vendored
Normal file
21
public/build/dist/css/all-c8eb2347.css
vendored
Normal file
File diff suppressed because one or more lines are too long
@@ -20,8 +20,12 @@ class ComponentTest extends AbstractTestCase
|
||||
|
||||
public function testGetComponents()
|
||||
{
|
||||
$components = factory('CachetHQ\Cachet\Models\Component', 3)->create();
|
||||
|
||||
$this->get('/api/v1/components');
|
||||
$this->seeJson(['data' => []]);
|
||||
$this->seeJson(['id' => (string) $components[0]->id]);
|
||||
$this->seeJson(['id' => (string) $components[1]->id]);
|
||||
$this->seeJson(['id' => (string) $components[2]->id]);
|
||||
$this->assertResponseOk();
|
||||
}
|
||||
|
||||
|
||||
@@ -20,14 +20,18 @@ class IncidentTest extends AbstractTestCase
|
||||
|
||||
public function testGetIncidents()
|
||||
{
|
||||
$incidents = factory('CachetHQ\Cachet\Models\Incident', 3)->create();
|
||||
|
||||
$this->get('/api/v1/incidents');
|
||||
$this->seeJson(['data' => []]);
|
||||
$this->seeJson(['id' => (string) $incidents[0]->id]);
|
||||
$this->seeJson(['id' => (string) $incidents[1]->id]);
|
||||
$this->seeJson(['id' => (string) $incidents[2]->id]);
|
||||
$this->assertResponseOk();
|
||||
}
|
||||
|
||||
public function testGetInvalidIncident()
|
||||
{
|
||||
$this->get('/api/v1/incidents/1');
|
||||
$this->get('/api/v1/incidents/0');
|
||||
$this->assertResponseStatus(404);
|
||||
}
|
||||
|
||||
|
||||
@@ -18,10 +18,26 @@ class MetricPointTest extends AbstractTestCase
|
||||
{
|
||||
use DatabaseMigrations;
|
||||
|
||||
public function testGetMetricPoint()
|
||||
{
|
||||
$metric = factory('CachetHQ\Cachet\Models\Metric')->create();
|
||||
$metricPoint = factory('CachetHQ\Cachet\Models\MetricPoint', 3)->create([
|
||||
'metric_id' => $metric->id,
|
||||
]);
|
||||
|
||||
$this->get("/api/v1/metrics/{$metric->id}/points");
|
||||
$this->seeJson(['id' => (string) $metricPoint[0]->id]);
|
||||
$this->seeJson(['id' => (string) $metricPoint[1]->id]);
|
||||
$this->seeJson(['id' => (string) $metricPoint[2]->id]);
|
||||
}
|
||||
|
||||
public function testPostMetricPointUnauthorized()
|
||||
{
|
||||
$metricPoint = factory('CachetHQ\Cachet\Models\MetricPoint')->create();
|
||||
$this->post('/api/v1/metrics/1/points');
|
||||
$metric = factory('CachetHQ\Cachet\Models\Metric')->create();
|
||||
$metricPoint = factory('CachetHQ\Cachet\Models\MetricPoint')->create([
|
||||
'metric_id' => $metric->id,
|
||||
]);
|
||||
$this->post("/api/v1/metrics/{$metric->id}/points");
|
||||
|
||||
$this->assertResponseStatus(401);
|
||||
$this->seeJson(['message' => 'You are not authorized to view this content.', 'status_code' => 401]);
|
||||
@@ -30,17 +46,24 @@ class MetricPointTest extends AbstractTestCase
|
||||
public function testPostMetricPoint()
|
||||
{
|
||||
$this->beUser();
|
||||
$metricPoint = factory('CachetHQ\Cachet\Models\MetricPoint')->create();
|
||||
|
||||
$this->post('/api/v1/metrics/1/points', $metricPoint->toArray());
|
||||
$metric = factory('CachetHQ\Cachet\Models\Metric')->create();
|
||||
$metricPoint = factory('CachetHQ\Cachet\Models\MetricPoint')->make([
|
||||
'metric_id' => $metric->id,
|
||||
]);
|
||||
|
||||
$this->post("/api/v1/metrics/{$metric->id}/points", $metricPoint->toArray());
|
||||
$this->seeJson(['value' => (string) $metricPoint->value]);
|
||||
}
|
||||
|
||||
public function testPutMetricPoint()
|
||||
{
|
||||
$this->beUser();
|
||||
$metricPoint = factory('CachetHQ\Cachet\Models\MetricPoint')->create();
|
||||
$this->put('/api/v1/metrics/1/points/1', [
|
||||
$metric = factory('CachetHQ\Cachet\Models\Metric')->create();
|
||||
$metricPoint = factory('CachetHQ\Cachet\Models\MetricPoint')->create([
|
||||
'metric_id' => $metric->id,
|
||||
]);
|
||||
$this->put("/api/v1/metrics/{$metric->id}/points/{$metricPoint->id}", [
|
||||
'value' => 999,
|
||||
]);
|
||||
$this->seeJson(['value' => '999']);
|
||||
@@ -49,8 +72,11 @@ class MetricPointTest extends AbstractTestCase
|
||||
public function testDeleteMetricPoint()
|
||||
{
|
||||
$this->beUser();
|
||||
$metricPoint = factory('CachetHQ\Cachet\Models\MetricPoint')->create();
|
||||
$this->delete('/api/v1/metrics/1/points/1');
|
||||
$metric = factory('CachetHQ\Cachet\Models\Metric')->create();
|
||||
$metricPoint = factory('CachetHQ\Cachet\Models\MetricPoint')->create([
|
||||
'metric_id' => $metric->id,
|
||||
]);
|
||||
$this->delete("/api/v1/metrics/{$metric->id}/points/{$metricPoint->id}");
|
||||
$this->assertResponseStatus(204);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,14 +20,18 @@ class MetricTest extends AbstractTestCase
|
||||
|
||||
public function testGetMetrics()
|
||||
{
|
||||
$metrics = factory('CachetHQ\Cachet\Models\Metric', 3)->create();
|
||||
|
||||
$this->get('/api/v1/metrics');
|
||||
$this->seeJson(['data' => []]);
|
||||
$this->seeJson(['id' => (string) $metrics[0]->id]);
|
||||
$this->seeJson(['id' => (string) $metrics[1]->id]);
|
||||
$this->seeJson(['id' => (string) $metrics[2]->id]);
|
||||
$this->assertResponseOk();
|
||||
}
|
||||
|
||||
public function testGetInvalidMetric()
|
||||
{
|
||||
$this->get('/api/v1/metrics/1');
|
||||
$this->get('/api/v1/metrics/0');
|
||||
$this->assertResponseStatus(404);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user