Merge pull request #2662 from CachetHQ/controller-resources
Rename controller methods following Laravel's resource controllers
This commit is contained in:
@@ -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 @@ class ComponentController extends AbstractApiController
|
||||
*
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function getComponent(Component $component)
|
||||
public function show(Component $component)
|
||||
{
|
||||
return $this->item($component);
|
||||
}
|
||||
@@ -67,7 +67,7 @@ class ComponentController extends AbstractApiController
|
||||
*
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function postComponents()
|
||||
public function store()
|
||||
{
|
||||
try {
|
||||
$component = dispatch(new CreateComponentCommand(
|
||||
@@ -108,7 +108,7 @@ class ComponentController extends AbstractApiController
|
||||
*
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function putComponent(Component $component)
|
||||
public function update(Component $component)
|
||||
{
|
||||
try {
|
||||
dispatch(new UpdateComponentCommand(
|
||||
@@ -148,7 +148,7 @@ class ComponentController extends AbstractApiController
|
||||
*
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function deleteComponent(Component $component)
|
||||
public function destroy(Component $component)
|
||||
{
|
||||
dispatch(new RemoveComponentCommand($component));
|
||||
|
||||
|
||||
@@ -52,7 +52,7 @@ class ComponentGroupController extends AbstractApiController
|
||||
*
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function getGroups()
|
||||
public function index()
|
||||
{
|
||||
$groups = ComponentGroup::query();
|
||||
if (!$this->guard->check()) {
|
||||
@@ -79,7 +79,7 @@ class ComponentGroupController extends AbstractApiController
|
||||
*
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function getGroup(ComponentGroup $group)
|
||||
public function show(ComponentGroup $group)
|
||||
{
|
||||
return $this->item($group);
|
||||
}
|
||||
@@ -89,7 +89,7 @@ class ComponentGroupController extends AbstractApiController
|
||||
*
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function postGroups()
|
||||
public function store()
|
||||
{
|
||||
try {
|
||||
$group = dispatch(new CreateComponentGroupCommand(
|
||||
@@ -112,7 +112,7 @@ class ComponentGroupController extends AbstractApiController
|
||||
*
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function putGroup(ComponentGroup $group)
|
||||
public function update(ComponentGroup $group)
|
||||
{
|
||||
try {
|
||||
$group = dispatch(new UpdateComponentGroupCommand(
|
||||
@@ -136,7 +136,7 @@ class ComponentGroupController extends AbstractApiController
|
||||
*
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function deleteGroup(ComponentGroup $group)
|
||||
public function destroy(ComponentGroup $group)
|
||||
{
|
||||
dispatch(new RemoveComponentGroupCommand($group));
|
||||
|
||||
|
||||
@@ -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 @@ class IncidentController extends AbstractApiController
|
||||
*
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function getIncident(Incident $incident)
|
||||
public function show(Incident $incident)
|
||||
{
|
||||
return $this->item($incident);
|
||||
}
|
||||
@@ -64,7 +64,7 @@ class IncidentController extends AbstractApiController
|
||||
*
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function postIncidents()
|
||||
public function store()
|
||||
{
|
||||
try {
|
||||
$incident = dispatch(new CreateIncidentCommand(
|
||||
@@ -95,7 +95,7 @@ class IncidentController extends AbstractApiController
|
||||
*
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function putIncident(Incident $incident)
|
||||
public function update(Incident $incident)
|
||||
{
|
||||
try {
|
||||
$incident = dispatch(new UpdateIncidentCommand(
|
||||
@@ -126,7 +126,7 @@ class IncidentController extends AbstractApiController
|
||||
*
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function deleteIncident(Incident $incident)
|
||||
public function destroy(Incident $incident)
|
||||
{
|
||||
dispatch(new RemoveIncidentCommand($incident));
|
||||
|
||||
|
||||
@@ -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 @@ class IncidentUpdateController extends AbstractApiController
|
||||
*
|
||||
* @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 @@ class IncidentUpdateController extends AbstractApiController
|
||||
*
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function postIncidentUpdate(Incident $incident)
|
||||
public function store(Incident $incident)
|
||||
{
|
||||
try {
|
||||
$update = dispatch(new CreateIncidentUpdateCommand(
|
||||
@@ -95,7 +95,7 @@ class IncidentUpdateController extends AbstractApiController
|
||||
*
|
||||
* @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 @@ class IncidentUpdateController extends AbstractApiController
|
||||
*
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function deleteIncidentUpdate(Incident $incident, IncidentUpdate $update)
|
||||
public function destroy(Incident $incident, IncidentUpdate $update)
|
||||
{
|
||||
try {
|
||||
dispatch(new RemoveIncidentUpdateCommand($update));
|
||||
|
||||
@@ -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 @@ class MetricController extends AbstractApiController
|
||||
*
|
||||
* @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 @@ class MetricController extends AbstractApiController
|
||||
*
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function putMetric(Metric $metric)
|
||||
public function update(Metric $metric)
|
||||
{
|
||||
try {
|
||||
$metric = dispatch(new UpdateMetricCommand(
|
||||
@@ -134,7 +120,7 @@ class MetricController extends AbstractApiController
|
||||
*
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function deleteMetric(Metric $metric)
|
||||
public function destroy(Metric $metric)
|
||||
{
|
||||
dispatch(new RemoveMetricCommand($metric));
|
||||
|
||||
|
||||
@@ -18,6 +18,7 @@ use CachetHQ\Cachet\Models\Metric;
|
||||
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 @@ class MetricPointController extends AbstractApiController
|
||||
*
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function postMetricPoints(Metric $metric)
|
||||
public function store(Metric $metric)
|
||||
{
|
||||
try {
|
||||
$metricPoint = dispatch(new CreateMetricPointCommand(
|
||||
@@ -65,7 +68,7 @@ class MetricPointController extends AbstractApiController
|
||||
*
|
||||
* @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 @@ class MetricPointController extends AbstractApiController
|
||||
*
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function deleteMetricPoint(Metric $metric, MetricPoint $metricPoint)
|
||||
public function destroy(Metric $metric, MetricPoint $metricPoint)
|
||||
{
|
||||
dispatch(new RemoveMetricPointCommand($metricPoint));
|
||||
|
||||
|
||||
@@ -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 @@ class ScheduleController extends AbstractApiController
|
||||
*
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function getSchedule(Schedule $schedule)
|
||||
public function show(Schedule $schedule)
|
||||
{
|
||||
return $this->item($schedule);
|
||||
}
|
||||
@@ -64,7 +64,7 @@ class ScheduleController extends AbstractApiController
|
||||
*
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function postSchedule()
|
||||
public function store()
|
||||
{
|
||||
try {
|
||||
$schedule = dispatch(new CreateScheduleCommand(
|
||||
@@ -89,7 +89,7 @@ class ScheduleController extends AbstractApiController
|
||||
*
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function putSchedule(Schedule $schedule)
|
||||
public function update(Schedule $schedule)
|
||||
{
|
||||
try {
|
||||
$schedule = dispatch(new UpdateScheduleCommand(
|
||||
@@ -115,7 +115,7 @@ class ScheduleController extends AbstractApiController
|
||||
*
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function deleteSchedule(Schedule $schedule)
|
||||
public function destroy(Schedule $schedule)
|
||||
{
|
||||
try {
|
||||
dispatch(new DeleteScheduleCommand($schedule));
|
||||
|
||||
@@ -13,9 +13,7 @@ namespace CachetHQ\Cachet\Http\Controllers\Api;
|
||||
|
||||
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 @@ class SubscriberController extends AbstractApiController
|
||||
*
|
||||
* @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 @@ class SubscriberController extends AbstractApiController
|
||||
*
|
||||
* @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();
|
||||
}
|
||||
}
|
||||
|
||||
37
app/Http/Controllers/Api/SubscriptionController.php
Normal file
37
app/Http/Controllers/Api/SubscriptionController.php
Normal file
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Cachet.
|
||||
*
|
||||
* (c) Alt Three Services Limited
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace CachetHQ\Cachet\Http\Controllers\Api;
|
||||
|
||||
use CachetHQ\Cachet\Bus\Commands\Subscriber\UnsubscribeSubscriptionCommand;
|
||||
use CachetHQ\Cachet\Models\Subscription;
|
||||
|
||||
/**
|
||||
* This is the subscription controller class.
|
||||
*
|
||||
* @author James Brooks <james@alt-three.com>
|
||||
*/
|
||||
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();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user