Changed namespacing to master CachetHq
This commit is contained in:
@@ -1,9 +0,0 @@
|
|||||||
<?php namespace Cachet\Repositories\Component;
|
|
||||||
|
|
||||||
use Cachet\Repositories\EloquentRepository;
|
|
||||||
|
|
||||||
class EloquentComponentRepository extends EloquentRepository implements ComponentRepository {
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
<?php namespace Cachet\Support\ServiceProviders;
|
|
||||||
|
|
||||||
use Illuminate\Support\ServiceProvider;
|
|
||||||
|
|
||||||
class RepositoryServiceProvider extends ServiceProvider {
|
|
||||||
|
|
||||||
public function register()
|
|
||||||
{
|
|
||||||
$this->app->bind('Cachet\Repositories\Component\ComponentRepository', 'Cachet\Repositories\Component\EloquentComponentRepository');
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
61
app/CachetHq/Cachet/Controllers/Api/ComponentController.php
Normal file
61
app/CachetHq/Cachet/Controllers/Api/ComponentController.php
Normal file
@@ -0,0 +1,61 @@
|
|||||||
|
<?php namespace CachetHq\Cachet\Controllers\Api;
|
||||||
|
|
||||||
|
use Dingo\Api\Routing\Controller as DingoController;
|
||||||
|
use Dingo\Api\Auth\Shield;
|
||||||
|
use CachetHq\Cachet\Repositories\Component\ComponentRepository;
|
||||||
|
|
||||||
|
class ComponentController extends DingoController {
|
||||||
|
|
||||||
|
protected $auth;
|
||||||
|
|
||||||
|
protected $component;
|
||||||
|
|
||||||
|
public function __construct(Shield $auth, ComponentRepository $component) {
|
||||||
|
$this->auth = $auth;
|
||||||
|
$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 Component
|
||||||
|
*/
|
||||||
|
public function getComponent($id) {
|
||||||
|
return $this->component->findOrFail($id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getComponentIncidents($id) {
|
||||||
|
return $this->component->incidents($id);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new component
|
||||||
|
*
|
||||||
|
* @return Component
|
||||||
|
*/
|
||||||
|
public function postComponents() {
|
||||||
|
$component = new Component(Input::all());
|
||||||
|
$component->user_id = $this->auth->user()->id;
|
||||||
|
if ($component->isValid()) {
|
||||||
|
try {
|
||||||
|
$component->saveOrFail();
|
||||||
|
return $component;
|
||||||
|
} catch (Exception $e) {
|
||||||
|
App::abort(500, $e->getMessage());
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
App::abort(404, $component->getErrors()->first());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
<?php namespace Cachet\Repositories\Component;
|
<?php namespace CachetHq\Cachet\Repositories\Component;
|
||||||
|
|
||||||
interface ComponentRepository {
|
interface ComponentRepository {
|
||||||
|
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
<?php namespace CachetHq\Cachet\Repositories\Component;
|
||||||
|
|
||||||
|
use CachetHq\Cachet\Repositories\EloquentRepository;
|
||||||
|
|
||||||
|
class EloquentComponentRepository extends EloquentRepository implements ComponentRepository {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
<?php namespace Cachet\Repositories;
|
<?php namespace CachetHq\Cachet\Repositories;
|
||||||
|
|
||||||
use Illuminate\Database\Eloquent\ModelNotFoundException;
|
use Illuminate\Database\Eloquent\ModelNotFoundException;
|
||||||
|
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
<?php namespace CachetHq\Cachet\Support\ServiceProviders;
|
||||||
|
|
||||||
|
use Illuminate\Support\ServiceProvider;
|
||||||
|
|
||||||
|
class RepositoryServiceProvider extends ServiceProvider {
|
||||||
|
|
||||||
|
public function register()
|
||||||
|
{
|
||||||
|
$this->app->bind('CachetHq\Cachet\Repositories\Component\ComponentRepository', 'CachetHq\Cachet\Repositories\Component\EloquentComponentRepository');
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -124,7 +124,7 @@ return array(
|
|||||||
|
|
||||||
'Dingo\Api\ApiServiceProvider',
|
'Dingo\Api\ApiServiceProvider',
|
||||||
|
|
||||||
'Cachet\Support\ServiceProviders\RepositoryServiceProvider',
|
'CachetHq\Cachet\Support\ServiceProviders\RepositoryServiceProvider',
|
||||||
|
|
||||||
),
|
),
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
<?php Cachet\Controllers\Api;
|
<?php Controllers\Api;
|
||||||
|
|
||||||
use \Dingo\Api\Routing\Controller as DingoController;
|
use Dingo\Api\Routing\Controller as DingoController;
|
||||||
use Dingo\Api\Auth\Shield;
|
use Dingo\Api\Auth\Shield;
|
||||||
use Cachet\Repositories\Component\ComponentRepository;
|
use Cachet\Repositories\Component\ComponentRepository;
|
||||||
|
|
||||||
|
|||||||
@@ -1,23 +1,23 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
Route::api(['version' => 'v1', 'prefix' => 'api'], function() {
|
Route::api(['version' => 'v1', 'prefix' => 'api', 'namespace' => 'Cachet\Controllers\Api'], function() {
|
||||||
|
|
||||||
Route::get('components', 'ApiController@getComponents');
|
Route::get('components', 'ComponentController@getComponents');
|
||||||
Route::get('components/{id}', 'ApiController@getComponent');
|
Route::get('components/{id}', 'ComponentController@getComponent');
|
||||||
Route::get('components/{id}/incidents', 'ApiController@getComponentIncidents');
|
Route::get('components/{id}/incidents', 'ComponentController@getComponentIncidents');
|
||||||
Route::get('incidents', 'ApiController@getIncidents');
|
Route::get('incidents', 'IncidentController@getIncidents');
|
||||||
Route::get('incidents/{id}', 'ApiController@getIncident');
|
Route::get('incidents/{id}', 'IncidentController@getIncident');
|
||||||
Route::get('metrics', 'ApiController@getMetrics');
|
Route::get('metrics', 'IncidentController@getMetrics');
|
||||||
Route::get('metrics/{id}', 'ApiController@getMetric');
|
Route::get('metrics/{id}', 'IncidentController@getMetric');
|
||||||
|
|
||||||
Route::group(['protected' => true], function() {
|
Route::group(['protected' => true], function() {
|
||||||
Route::post('components', 'ApiController@postComponents');
|
Route::post('components', 'ComponentController@postComponents');
|
||||||
Route::post('incidents', 'ApiController@postIncidents');
|
Route::post('incidents', 'IncidentController@postIncidents');
|
||||||
Route::post('metrics', 'ApiController@postMetrics');
|
Route::post('metrics', 'IncidentController@postMetrics');
|
||||||
|
|
||||||
Route::put('components/{id}', 'ApiController@putComponent');
|
Route::put('components/{id}', 'ComponentController@putComponent');
|
||||||
Route::put('incidents/{id}', 'ApiController@putIncident');
|
Route::put('incidents/{id}', 'IncidentController@putIncident');
|
||||||
Route::put('metrics/{id}', 'ApiController@putMetric');
|
Route::put('metrics/{id}', 'IncidentController@putMetric');
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -22,7 +22,7 @@
|
|||||||
"app/filters"
|
"app/filters"
|
||||||
],
|
],
|
||||||
"psr-4": {
|
"psr-4": {
|
||||||
"Cachet\\": "app/Cachet"
|
"CachetHq\\": "app/CachetHq"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"extra": {
|
"extra": {
|
||||||
|
|||||||
Reference in New Issue
Block a user