From 85c10f1436eb67aa0c0a9ed2ed536294b7c87cfc Mon Sep 17 00:00:00 2001 From: James Brooks Date: Wed, 26 Jul 2017 08:31:11 -0400 Subject: [PATCH] Rename controller methods following Laravel's resource controllers --- .../Controllers/Api/ComponentController.php | 10 +-- .../Api/ComponentGroupController.php | 10 +-- .../Controllers/Api/IncidentController.php | 10 +-- .../Api/IncidentUpdateController.php | 10 +-- app/Http/Controllers/Api/MetricController.php | 24 ++---- .../Controllers/Api/MetricPointController.php | 13 ++-- .../Controllers/Api/ScheduleController.php | 10 +-- .../Controllers/Api/SubscriberController.php | 22 +----- .../Api/SubscriptionController.php | 37 +++++++++ app/Http/Routes/ApiRoutes.php | 76 +++++++++---------- 10 files changed, 116 insertions(+), 106 deletions(-) create mode 100644 app/Http/Controllers/Api/SubscriptionController.php diff --git a/app/Http/Controllers/Api/ComponentController.php b/app/Http/Controllers/Api/ComponentController.php index de811f3bccc8..2717d626f7c0 100644 --- a/app/Http/Controllers/Api/ComponentController.php +++ b/app/Http/Controllers/Api/ComponentController.php @@ -29,7 +29,7 @@ class ComponentController extends AbstractApiController * * @return \Illuminate\Http\JsonResponse */ - public function getComponents() + public function index() { if (app(Guard::class)->check()) { $components = Component::query(); @@ -57,7 +57,7 @@ public function getComponents() * * @return \Illuminate\Http\JsonResponse */ - public function getComponent(Component $component) + public function show(Component $component) { return $this->item($component); } @@ -67,7 +67,7 @@ public function getComponent(Component $component) * * @return \Illuminate\Http\JsonResponse */ - public function postComponents() + public function store() { try { $component = dispatch(new CreateComponentCommand( @@ -108,7 +108,7 @@ public function postComponents() * * @return \Illuminate\Http\JsonResponse */ - public function putComponent(Component $component) + public function update(Component $component) { try { dispatch(new UpdateComponentCommand( @@ -148,7 +148,7 @@ public function putComponent(Component $component) * * @return \Illuminate\Http\JsonResponse */ - public function deleteComponent(Component $component) + public function destroy(Component $component) { dispatch(new RemoveComponentCommand($component)); diff --git a/app/Http/Controllers/Api/ComponentGroupController.php b/app/Http/Controllers/Api/ComponentGroupController.php index 38f54767738c..7e7c65a7c408 100644 --- a/app/Http/Controllers/Api/ComponentGroupController.php +++ b/app/Http/Controllers/Api/ComponentGroupController.php @@ -52,7 +52,7 @@ public function __construct(Guard $guard) * * @return \Illuminate\Http\JsonResponse */ - public function getGroups() + public function index() { $groups = ComponentGroup::query(); if (!$this->guard->check()) { @@ -79,7 +79,7 @@ public function getGroups() * * @return \Illuminate\Http\JsonResponse */ - public function getGroup(ComponentGroup $group) + public function show(ComponentGroup $group) { return $this->item($group); } @@ -89,7 +89,7 @@ public function getGroup(ComponentGroup $group) * * @return \Illuminate\Http\JsonResponse */ - public function postGroups() + public function store() { try { $group = dispatch(new CreateComponentGroupCommand( @@ -112,7 +112,7 @@ public function postGroups() * * @return \Illuminate\Http\JsonResponse */ - public function putGroup(ComponentGroup $group) + public function update(ComponentGroup $group) { try { $group = dispatch(new UpdateComponentGroupCommand( @@ -136,7 +136,7 @@ public function putGroup(ComponentGroup $group) * * @return \Illuminate\Http\JsonResponse */ - public function deleteGroup(ComponentGroup $group) + public function destroy(ComponentGroup $group) { dispatch(new RemoveComponentGroupCommand($group)); diff --git a/app/Http/Controllers/Api/IncidentController.php b/app/Http/Controllers/Api/IncidentController.php index ac5cd82a5940..718be542650d 100644 --- a/app/Http/Controllers/Api/IncidentController.php +++ b/app/Http/Controllers/Api/IncidentController.php @@ -28,7 +28,7 @@ class IncidentController extends AbstractApiController * * @return \Illuminate\Http\JsonResponse */ - public function getIncidents() + public function index() { $incidentVisibility = app(Guard::class)->check() ? 0 : 1; @@ -54,7 +54,7 @@ public function getIncidents() * * @return \Illuminate\Http\JsonResponse */ - public function getIncident(Incident $incident) + public function show(Incident $incident) { return $this->item($incident); } @@ -64,7 +64,7 @@ public function getIncident(Incident $incident) * * @return \Illuminate\Http\JsonResponse */ - public function postIncidents() + public function store() { try { $incident = dispatch(new CreateIncidentCommand( @@ -95,7 +95,7 @@ public function postIncidents() * * @return \Illuminate\Http\JsonResponse */ - public function putIncident(Incident $incident) + public function update(Incident $incident) { try { $incident = dispatch(new UpdateIncidentCommand( @@ -126,7 +126,7 @@ public function putIncident(Incident $incident) * * @return \Illuminate\Http\JsonResponse */ - public function deleteIncident(Incident $incident) + public function destroy(Incident $incident) { dispatch(new RemoveIncidentCommand($incident)); diff --git a/app/Http/Controllers/Api/IncidentUpdateController.php b/app/Http/Controllers/Api/IncidentUpdateController.php index 73faf3794696..a12bca89c148 100644 --- a/app/Http/Controllers/Api/IncidentUpdateController.php +++ b/app/Http/Controllers/Api/IncidentUpdateController.php @@ -36,7 +36,7 @@ class IncidentUpdateController extends AbstractApiController * * @return \Illuminate\Http\JsonResponse */ - public function getIncidentUpdates(Incident $incident) + public function index(Incident $incident) { $updates = IncidentUpdate::orderBy('created_at', 'desc'); @@ -59,7 +59,7 @@ public function getIncidentUpdates(Incident $incident) * * @return \Illuminate\Http\JsonResponse */ - public function getIncidentUpdate(Incident $incident, IncidentUpdate $update) + public function show(Incident $incident, IncidentUpdate $update) { return $this->item($update); } @@ -71,7 +71,7 @@ public function getIncidentUpdate(Incident $incident, IncidentUpdate $update) * * @return \Illuminate\Http\JsonResponse */ - public function postIncidentUpdate(Incident $incident) + public function store(Incident $incident) { try { $update = dispatch(new CreateIncidentUpdateCommand( @@ -95,7 +95,7 @@ public function postIncidentUpdate(Incident $incident) * * @return \Illuminate\Http\JsonResponse */ - public function putIncidentUpdate(Incident $incident, IncidentUpdate $update) + public function update(Incident $incident, IncidentUpdate $update) { try { $update = dispatch(new UpdateIncidentUpdateCommand( @@ -119,7 +119,7 @@ public function putIncidentUpdate(Incident $incident, IncidentUpdate $update) * * @return \Illuminate\Http\JsonResponse */ - public function deleteIncidentUpdate(Incident $incident, IncidentUpdate $update) + public function destroy(Incident $incident, IncidentUpdate $update) { try { dispatch(new RemoveIncidentUpdateCommand($update)); diff --git a/app/Http/Controllers/Api/MetricController.php b/app/Http/Controllers/Api/MetricController.php index 39d6fc2018cd..fd7dbe070e30 100644 --- a/app/Http/Controllers/Api/MetricController.php +++ b/app/Http/Controllers/Api/MetricController.php @@ -27,7 +27,7 @@ class MetricController extends AbstractApiController * * @return \Illuminate\Database\Eloquent\Collection */ - public function getMetrics() + public function index() { $metrics = Metric::query(); @@ -49,31 +49,17 @@ public function getMetrics() * * @return \Illuminate\Http\JsonResponse */ - public function getMetric(Metric $metric) + public function show(Metric $metric) { return $this->item($metric); } - /** - * Get all metric points. - * - * @param \CachetHQ\Cachet\Models\Metric $metric - * - * @return \Illuminate\Database\Eloquent\Collection - */ - public function getMetricPoints(Metric $metric) - { - $points = $metric->points()->paginate(Binput::get('per_page', 20)); - - return $this->paginator($points, Request::instance()); - } - /** * Create a new metric. * * @return \Illuminate\Http\JsonResponse */ - public function postMetrics() + public function store() { try { $metric = dispatch(new CreateMetricCommand( @@ -103,7 +89,7 @@ public function postMetrics() * * @return \Illuminate\Http\JsonResponse */ - public function putMetric(Metric $metric) + public function update(Metric $metric) { try { $metric = dispatch(new UpdateMetricCommand( @@ -134,7 +120,7 @@ public function putMetric(Metric $metric) * * @return \Illuminate\Http\JsonResponse */ - public function deleteMetric(Metric $metric) + public function destroy(Metric $metric) { dispatch(new RemoveMetricCommand($metric)); diff --git a/app/Http/Controllers/Api/MetricPointController.php b/app/Http/Controllers/Api/MetricPointController.php index 09ddff66ed81..c5cd6f1f12c4 100644 --- a/app/Http/Controllers/Api/MetricPointController.php +++ b/app/Http/Controllers/Api/MetricPointController.php @@ -18,6 +18,7 @@ use CachetHQ\Cachet\Models\MetricPoint; use GrahamCampbell\Binput\Facades\Binput; use Illuminate\Database\QueryException; +use Illuminate\Support\Facades\Request; use Symfony\Component\HttpKernel\Exception\BadRequestHttpException; class MetricPointController extends AbstractApiController @@ -30,9 +31,11 @@ class MetricPointController extends AbstractApiController * * @return \Illuminate\Http\JsonResponse */ - public function getMetricPoints(Metric $metric, MetricPoint $metricPoint) + public function index(Metric $metric, MetricPoint $metricPoint) { - return $this->item($metricPoint); + $points = $metric->points()->paginate(Binput::get('per_page', 20)); + + return $this->paginator($points, Request::instance()); } /** @@ -42,7 +45,7 @@ public function getMetricPoints(Metric $metric, MetricPoint $metricPoint) * * @return \Illuminate\Http\JsonResponse */ - public function postMetricPoints(Metric $metric) + public function store(Metric $metric) { try { $metricPoint = dispatch(new CreateMetricPointCommand( @@ -65,7 +68,7 @@ public function postMetricPoints(Metric $metric) * * @return \Illuminate\Http\JsonResponse */ - public function putMetricPoint(Metric $metric, MetricPoint $metricPoint) + public function update(Metric $metric, MetricPoint $metricPoint) { $metricPoint = dispatch(new UpdateMetricPointCommand( $metricPoint, @@ -85,7 +88,7 @@ public function putMetricPoint(Metric $metric, MetricPoint $metricPoint) * * @return \Illuminate\Http\JsonResponse */ - public function deleteMetricPoint(Metric $metric, MetricPoint $metricPoint) + public function destroy(Metric $metric, MetricPoint $metricPoint) { dispatch(new RemoveMetricPointCommand($metricPoint)); diff --git a/app/Http/Controllers/Api/ScheduleController.php b/app/Http/Controllers/Api/ScheduleController.php index 2838d2958f8e..6fe120391b0d 100644 --- a/app/Http/Controllers/Api/ScheduleController.php +++ b/app/Http/Controllers/Api/ScheduleController.php @@ -32,7 +32,7 @@ class ScheduleController extends AbstractApiController * * @return \Illuminate\Http\JsonResponse */ - public function getSchedules() + public function index() { $schedule = Schedule::whereRaw('1 = 1'); @@ -54,7 +54,7 @@ public function getSchedules() * * @return \Illuminate\Http\JsonResponse */ - public function getSchedule(Schedule $schedule) + public function show(Schedule $schedule) { return $this->item($schedule); } @@ -64,7 +64,7 @@ public function getSchedule(Schedule $schedule) * * @return \Illuminate\Http\JsonResponse */ - public function postSchedule() + public function store() { try { $schedule = dispatch(new CreateScheduleCommand( @@ -89,7 +89,7 @@ public function postSchedule() * * @return \Illuminate\Http\JsonResponse */ - public function putSchedule(Schedule $schedule) + public function update(Schedule $schedule) { try { $schedule = dispatch(new UpdateScheduleCommand( @@ -115,7 +115,7 @@ public function putSchedule(Schedule $schedule) * * @return \Illuminate\Http\JsonResponse */ - public function deleteSchedule(Schedule $schedule) + public function destroy(Schedule $schedule) { try { dispatch(new DeleteScheduleCommand($schedule)); diff --git a/app/Http/Controllers/Api/SubscriberController.php b/app/Http/Controllers/Api/SubscriberController.php index e7dfb1a76fcc..5a8b11788373 100644 --- a/app/Http/Controllers/Api/SubscriberController.php +++ b/app/Http/Controllers/Api/SubscriberController.php @@ -13,9 +13,7 @@ use CachetHQ\Cachet\Bus\Commands\Subscriber\SubscribeSubscriberCommand; use CachetHQ\Cachet\Bus\Commands\Subscriber\UnsubscribeSubscriberCommand; -use CachetHQ\Cachet\Bus\Commands\Subscriber\UnsubscribeSubscriptionCommand; use CachetHQ\Cachet\Models\Subscriber; -use CachetHQ\Cachet\Models\Subscription; use GrahamCampbell\Binput\Facades\Binput; use Illuminate\Contracts\Config\Repository; use Illuminate\Database\QueryException; @@ -35,7 +33,7 @@ class SubscriberController extends AbstractApiController * * @return \Illuminate\Http\JsonResponse */ - public function getSubscribers() + public function index() { $subscribers = Subscriber::paginate(Binput::get('per_page', 20)); @@ -47,7 +45,7 @@ public function getSubscribers() * * @return \Illuminate\Http\JsonResponse */ - public function postSubscribers() + public function store() { $verified = Binput::get('verify', app(Repository::class)->get('setting.skip_subscriber_verification')); @@ -67,24 +65,10 @@ public function postSubscribers() * * @return \Illuminate\Http\JsonResponse */ - public function deleteSubscriber(Subscriber $subscriber) + public function destroy(Subscriber $subscriber) { dispatch(new UnsubscribeSubscriberCommand($subscriber)); return $this->noContent(); } - - /** - * Delete a subscriber. - * - * @param \CachetHQ\Cachet\Models\Subscriber $subscriber - * - * @return \Illuminate\Http\JsonResponse - */ - public function deleteSubscription(Subscription $subscriber) - { - dispatch(new UnsubscribeSubscriptionCommand($subscriber)); - - return $this->noContent(); - } } diff --git a/app/Http/Controllers/Api/SubscriptionController.php b/app/Http/Controllers/Api/SubscriptionController.php new file mode 100644 index 000000000000..a7372d080c44 --- /dev/null +++ b/app/Http/Controllers/Api/SubscriptionController.php @@ -0,0 +1,37 @@ + + */ +class SubscriptionController extends AbstractApiController +{ + /** + * Delete a subscription. + * + * @param \CachetHQ\Cachet\Models\Subscription $subscription + * + * @return \Illuminate\Http\JsonResponse + */ + public function destroy(Subscription $subscription) + { + dispatch(new UnsubscribeSubscriptionCommand($subscription)); + + return $this->noContent(); + } +} diff --git a/app/Http/Routes/ApiRoutes.php b/app/Http/Routes/ApiRoutes.php index 9ec12e58015e..3408123a1278 100644 --- a/app/Http/Routes/ApiRoutes.php +++ b/app/Http/Routes/ApiRoutes.php @@ -45,54 +45,54 @@ public function map(Registrar $router) $router->get('version', 'GeneralController@version'); $router->get('status', 'GeneralController@status'); - $router->get('components', 'ComponentController@getComponents'); - $router->get('components/groups', 'ComponentGroupController@getGroups'); - $router->get('components/groups/{component_group}', 'ComponentGroupController@getGroup'); - $router->get('components/{component}', 'ComponentController@getComponent'); + $router->get('components', 'ComponentController@index'); + $router->get('components/groups', 'ComponentGroupController@index'); + $router->get('components/groups/{component_group}', 'ComponentGroupController@show'); + $router->get('components/{component}', 'ComponentController@show'); - $router->get('incidents', 'IncidentController@getIncidents'); - $router->get('incidents/{incident}', 'IncidentController@getIncident'); + $router->get('incidents', 'IncidentController@index'); + $router->get('incidents/{incident}', 'IncidentController@show'); - $router->get('incidents/{incident}/updates', 'IncidentUpdateController@getIncidentUpdates'); - $router->get('incidents/{incident}/updates/{update}', 'IncidentUpdateController@getIncidentUpdate'); + $router->get('incidents/{incident}/updates', 'IncidentUpdateController@index'); + $router->get('incidents/{incident}/updates/{update}', 'IncidentUpdateController@show'); - $router->get('metrics', 'MetricController@getMetrics'); - $router->get('metrics/{metric}', 'MetricController@getMetric'); - $router->get('metrics/{metric}/points', 'MetricController@getMetricPoints'); + $router->get('metrics', 'MetricController@index'); + $router->get('metrics/{metric}', 'MetricController@show'); + $router->get('metrics/{metric}/points', 'MetricPointController@index'); - $router->get('schedules', 'ScheduleController@getSchedules'); - $router->get('schedules/{schedule}', 'ScheduleController@getSchedule'); + $router->get('schedules', 'ScheduleController@index'); + $router->get('schedules/{schedule}', 'ScheduleController@show'); }); $router->group(['middleware' => ['auth.api:true']], function (Registrar $router) { - $router->get('subscribers', 'SubscriberController@getSubscribers'); + $router->get('subscribers', 'SubscriberController@index'); - $router->post('components', 'ComponentController@postComponents'); - $router->post('components/groups', 'ComponentGroupController@postGroups'); - $router->post('incidents', 'IncidentController@postIncidents'); - $router->post('incidents/{incident}/updates', 'IncidentUpdateController@postIncidentUpdate'); - $router->post('metrics', 'MetricController@postMetrics'); - $router->post('metrics/{metric}/points', 'MetricPointController@postMetricPoints'); - $router->post('schedules', 'ScheduleController@postSchedule'); - $router->post('subscribers', 'SubscriberController@postSubscribers'); + $router->post('components', 'ComponentController@store'); + $router->post('components/groups', 'ComponentGroupController@store'); + $router->post('incidents', 'IncidentController@store'); + $router->post('incidents/{incident}/updates', 'IncidentUpdateController@store'); + $router->post('metrics', 'MetricController@store'); + $router->post('metrics/{metric}/points', 'MetricPointController@store'); + $router->post('schedules', 'ScheduleController@store'); + $router->post('subscribers', 'SubscriberController@store'); - $router->put('components/groups/{component_group}', 'ComponentGroupController@putGroup'); - $router->put('components/{component}', 'ComponentController@putComponent'); - $router->put('incidents/{incident}', 'IncidentController@putIncident'); - $router->put('incidents/{incident}/updates/{update}', 'IncidentUpdateController@putIncidentUpdate'); - $router->put('metrics/{metric}', 'MetricController@putMetric'); - $router->put('metrics/{metric}/points/{metric_point}', 'MetricPointController@putMetricPoint'); - $router->put('schedules/{schedule}', 'ScheduleController@putSchedule'); + $router->put('components/groups/{component_group}', 'ComponentGroupController@update'); + $router->put('components/{component}', 'ComponentController@update'); + $router->put('incidents/{incident}', 'IncidentController@update'); + $router->put('incidents/{incident}/updates/{update}', 'IncidentUpdateController@update'); + $router->put('metrics/{metric}', 'MetricController@update'); + $router->put('metrics/{metric}/points/{metric_point}', 'MetricPointController@update'); + $router->put('schedules/{schedule}', 'ScheduleController@update'); - $router->delete('components/groups/{component_group}', 'ComponentGroupController@deleteGroup'); - $router->delete('components/{component}', 'ComponentController@deleteComponent'); - $router->delete('incidents/{incident}', 'IncidentController@deleteIncident'); - $router->delete('incidents/{incident}/updates/{update}', 'IncidentUpdateController@deleteIncidentUpdate'); - $router->delete('metrics/{metric}', 'MetricController@deleteMetric'); - $router->delete('metrics/{metric}/points/{metric_point}', 'MetricPointController@deleteMetricPoint'); - $router->delete('schedules/{schedule}', 'ScheduleController@deleteSchedule'); - $router->delete('subscribers/{subscriber}', 'SubscriberController@deleteSubscriber'); - $router->delete('subscriptions/{subscription}', 'SubscriberController@deleteSubscription'); + $router->delete('components/groups/{component_group}', 'ComponentGroupController@destroy'); + $router->delete('components/{component}', 'ComponentController@destroy'); + $router->delete('incidents/{incident}', 'IncidentController@destroy'); + $router->delete('incidents/{incident}/updates/{update}', 'IncidentUpdateController@destroy'); + $router->delete('metrics/{metric}', 'MetricController@destroy'); + $router->delete('metrics/{metric}/points/{metric_point}', 'MetricPointController@destroy'); + $router->delete('schedules/{schedule}', 'ScheduleController@destroy'); + $router->delete('subscribers/{subscriber}', 'SubscriberController@destroy'); + $router->delete('subscriptions/{subscription}', 'SubscriptionController@destroy'); }); }); }