Cachet/app/Http/Controllers/Api/IncidentController.php

97 lines
2.1 KiB
PHP
Raw Normal View History

<?php
/*
* This file is part of Cachet.
*
* (c) James Brooks <james@cachethq.io>
*
* 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;
2014-12-20 21:20:17 +00:00
use CachetHQ\Cachet\Repositories\Incident\IncidentRepository;
2015-01-02 12:05:50 +00:00
use GrahamCampbell\Binput\Facades\Binput;
2015-03-20 18:30:45 -06:00
use Illuminate\Http\Request;
2015-03-20 18:30:45 -06:00
class IncidentController extends AbstractApiController
2014-12-20 21:20:17 +00:00
{
2015-01-01 20:13:53 +00:00
/**
* The incident repository instance.
*
* @var \CachetHQ\Cachet\Repositories\Incident\IncidentRepository
*/
protected $incident;
2015-01-01 20:13:53 +00:00
/**
* Create a new incident controller instance.
*
* @param \CachetHQ\Cachet\Repositories\Incident\IncidentRepository $incident
*/
2014-12-20 21:20:17 +00:00
public function __construct(IncidentRepository $incident)
{
$this->incident = $incident;
}
/**
2014-12-30 18:19:22 +00:00
* Get all incidents.
*
* @return \Illuminate\Database\Eloquent\Collection
*/
2015-03-20 18:30:45 -06:00
public function getIncidents(Request $request)
2014-12-20 21:20:17 +00:00
{
2015-02-17 16:00:38 -06:00
$incidents = $this->incident->paginate(Binput::get('per_page', 20));
2015-03-20 18:30:45 -06:00
return $this->paginator($incidents, $request);
}
2014-11-26 16:08:47 +00:00
/**
2014-12-30 18:19:22 +00:00
* Get a single incident.
*
* @param int $id
*
* @return \CachetHQ\Cachet\Models\Incident
*/
2014-12-20 21:20:17 +00:00
public function getIncident($id)
{
return $this->incident->findOrFail($id);
}
2014-11-26 16:08:47 +00:00
/**
2014-12-30 18:19:22 +00:00
* Create a new incident.
*
* @return \CachetHQ\Cachet\Models\Incident
*/
2014-12-20 21:20:17 +00:00
public function postIncidents()
{
2015-01-02 12:05:50 +00:00
return $this->incident->create($this->auth->user()->id, Binput::all());
}
/**
2014-12-30 18:19:22 +00:00
* Update an existing incident.
*
* @param int $id
*
* @return \CachetHQ\Cachet\Models\Incident
*/
2014-12-20 21:20:17 +00:00
public function putIncident($id)
{
2015-01-02 12:05:50 +00:00
return $this->incident->update($id, Binput::all());
}
2015-01-14 01:50:58 -06:00
/**
* Delete an existing incident.
*
* @param int $id
*
* @return \Dingo\Api\Http\Response
*/
public function deleteIncident($id)
{
$this->incident->destroy($id);
2015-03-20 18:30:45 -06:00
return $this->noContent();
2015-01-14 01:50:58 -06:00
}
}