Merge pull request #1271 from cachethq/controllers

Minor controller cleanup
This commit is contained in:
Graham Campbell 2015-12-23 15:00:04 +00:00
commit cb18362241
7 changed files with 22 additions and 37 deletions

View File

@ -20,7 +20,7 @@ use GrahamCampbell\Binput\Facades\Binput;
use Illuminate\Contracts\Auth\Guard;
use Illuminate\Database\QueryException;
use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Request;
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
class ComponentController extends AbstractApiController
@ -30,20 +30,17 @@ class ComponentController extends AbstractApiController
/**
* Get all components.
*
* @param \Symfony\Component\HttpFoundation\Request $request
* @param \Illuminate\Contracts\Auth\Guard $auth
*
* @return \Illuminate\Http\JsonResponse
*/
public function getComponents(Request $request, Guard $auth)
public function getComponents()
{
if ($auth->check()) {
if (app(Guard::class)->check()) {
$components = Component::whereRaw('1 = 1');
} else {
$components = Component::enabled();
}
return $this->paginator($components->paginate(Binput::get('per_page', 20)), $request);
return $this->paginator($components->paginate(Binput::get('per_page', 20)), Request::instance());
}
/**

View File

@ -18,7 +18,7 @@ use CachetHQ\Cachet\Models\ComponentGroup;
use GrahamCampbell\Binput\Facades\Binput;
use Illuminate\Database\QueryException;
use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Request;
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
class ComponentGroupController extends AbstractApiController
@ -28,15 +28,13 @@ class ComponentGroupController extends AbstractApiController
/**
* Get all groups.
*
* @param \Symfony\Component\HttpFoundation\Request $request
*
* @return \Illuminate\Http\JsonResponse
*/
public function getGroups(Request $request)
public function getGroups()
{
$groups = ComponentGroup::paginate(Binput::get('per_page', 20));
return $this->paginator($groups, $request);
return $this->paginator($groups, Request::instance());
}
/**

View File

@ -19,7 +19,7 @@ use GrahamCampbell\Binput\Facades\Binput;
use Illuminate\Contracts\Auth\Guard;
use Illuminate\Database\QueryException;
use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Request;
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
class IncidentController extends AbstractApiController
@ -29,18 +29,15 @@ class IncidentController extends AbstractApiController
/**
* Get all incidents.
*
* @param \Symfony\Component\HttpFoundation\Request $request
* @param \Illuminate\Contracts\Auth\Guard $auth
*
* @return \Illuminate\Http\JsonResponse
*/
public function getIncidents(Request $request, Guard $auth)
public function getIncidents()
{
$incidentVisibility = $auth->check() ? 0 : 1;
$incidentVisibility = app(Guard::class)->check() ? 0 : 1;
$incidents = Incident::where('visible', '>=', $incidentVisibility)->paginate(Binput::get('per_page', 20));
return $this->paginator($incidents, $request);
return $this->paginator($incidents, Request::instance());
}
/**
@ -58,11 +55,9 @@ class IncidentController extends AbstractApiController
/**
* Create a new incident.
*
* @param \Illuminate\Contracts\Auth\Guard $auth
*
* @return \Illuminate\Http\JsonResponse
*/
public function postIncidents(Guard $auth)
public function postIncidents()
{
try {
$incident = $this->dispatch(new ReportIncidentCommand(

View File

@ -18,7 +18,7 @@ use CachetHQ\Cachet\Models\Metric;
use GrahamCampbell\Binput\Facades\Binput;
use Illuminate\Database\QueryException;
use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Request;
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
class MetricController extends AbstractApiController
@ -28,15 +28,13 @@ class MetricController extends AbstractApiController
/**
* Get all metrics.
*
* @param \Symfony\Component\HttpFoundation\Request $request
*
* @return \Illuminate\Database\Eloquent\Collection
*/
public function getMetrics(Request $request)
public function getMetrics()
{
$metrics = Metric::paginate(Binput::get('per_page', 20));
return $this->paginator($metrics, $request);
return $this->paginator($metrics, Request::instance());
}
/**

View File

@ -17,7 +17,7 @@ use CachetHQ\Cachet\Models\Subscriber;
use GrahamCampbell\Binput\Facades\Binput;
use Illuminate\Database\QueryException;
use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Request;
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
class SubscriberController extends AbstractApiController
@ -27,15 +27,13 @@ class SubscriberController extends AbstractApiController
/**
* Get all subscribers.
*
* @param \Symfony\Component\HttpFoundation\Request $request
*
* @return \Illuminate\Http\JsonResponse
*/
public function getSubscribers(Request $request)
public function getSubscribers()
{
$subscribers = Subscriber::paginate(Binput::get('per_page', 20));
return $this->paginator($subscribers, $request);
return $this->paginator($subscribers, Request::instance());
}
/**

View File

@ -134,17 +134,16 @@ class ScheduleController extends Controller
/**
* Updates the given incident.
*
* @param \CachetHQ\Cachet\Models\Incident $schedule
* @param \CachetHQ\Cachet\Dates\DateFactory $dates
* @param \CachetHQ\Cachet\Models\Incident $schedule
*
* @return \Illuminate\Http\RedirectResponse
*/
public function editScheduleAction(Incident $schedule, DateFactory $dates)
public function editScheduleAction(Incident $schedule)
{
$scheduleData = Binput::get('incident');
// Parse the schedule date.
$scheduledAt = $dates->createNormalized('d/m/Y H:i', $scheduleData['scheduled_at']);
$scheduledAt = app(DateFactory::class)->createNormalized('d/m/Y H:i', $scheduleData['scheduled_at']);
if ($scheduledAt->isPast()) {
$messageBag = new MessageBag();

View File

@ -99,7 +99,7 @@ class FeedController extends Controller
* @param \CachetHQ\Cachet\Models\Incident $incident
* @param bool $isRss
*/
private function feedAddItem($incident, $isRss)
private function feedAddItem(Incident $incident, $isRss)
{
$this->feed->add(
$incident->name,