Skip to content

Commit

Permalink
Merge pull request #2662 from CachetHQ/controller-resources
Browse files Browse the repository at this point in the history
Rename controller methods following Laravel's resource controllers
  • Loading branch information
jbrooksuk committed Jul 26, 2017
2 parents 77c7fb3 + 85c10f1 commit 6c84d89
Show file tree
Hide file tree
Showing 10 changed files with 116 additions and 106 deletions.
10 changes: 5 additions & 5 deletions app/Http/Controllers/Api/ComponentController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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);
}
Expand All @@ -67,7 +67,7 @@ public function getComponent(Component $component)
*
* @return \Illuminate\Http\JsonResponse
*/
public function postComponents()
public function store()
{
try {
$component = dispatch(new CreateComponentCommand(
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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));

Expand Down
10 changes: 5 additions & 5 deletions app/Http/Controllers/Api/ComponentGroupController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand All @@ -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);
}
Expand All @@ -89,7 +89,7 @@ public function getGroup(ComponentGroup $group)
*
* @return \Illuminate\Http\JsonResponse
*/
public function postGroups()
public function store()
{
try {
$group = dispatch(new CreateComponentGroupCommand(
Expand All @@ -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(
Expand All @@ -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));

Expand Down
10 changes: 5 additions & 5 deletions app/Http/Controllers/Api/IncidentController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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);
}
Expand All @@ -64,7 +64,7 @@ public function getIncident(Incident $incident)
*
* @return \Illuminate\Http\JsonResponse
*/
public function postIncidents()
public function store()
{
try {
$incident = dispatch(new CreateIncidentCommand(
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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));

Expand Down
10 changes: 5 additions & 5 deletions app/Http/Controllers/Api/IncidentUpdateController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand All @@ -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);
}
Expand All @@ -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(
Expand All @@ -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(
Expand All @@ -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));
Expand Down
24 changes: 5 additions & 19 deletions app/Http/Controllers/Api/MetricController.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class MetricController extends AbstractApiController
*
* @return \Illuminate\Database\Eloquent\Collection
*/
public function getMetrics()
public function index()
{
$metrics = Metric::query();

Expand All @@ -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(
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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));

Expand Down
13 changes: 8 additions & 5 deletions app/Http/Controllers/Api/MetricPointController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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());
}

/**
Expand All @@ -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(
Expand All @@ -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,
Expand All @@ -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));

Expand Down
10 changes: 5 additions & 5 deletions app/Http/Controllers/Api/ScheduleController.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class ScheduleController extends AbstractApiController
*
* @return \Illuminate\Http\JsonResponse
*/
public function getSchedules()
public function index()
{
$schedule = Schedule::whereRaw('1 = 1');

Expand All @@ -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);
}
Expand All @@ -64,7 +64,7 @@ public function getSchedule(Schedule $schedule)
*
* @return \Illuminate\Http\JsonResponse
*/
public function postSchedule()
public function store()
{
try {
$schedule = dispatch(new CreateScheduleCommand(
Expand All @@ -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(
Expand All @@ -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));
Expand Down
22 changes: 3 additions & 19 deletions app/Http/Controllers/Api/SubscriberController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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));

Expand All @@ -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'));

Expand All @@ -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();
}
}
Loading

0 comments on commit 6c84d89

Please sign in to comment.