2014-11-26 23:20:31 +00:00
|
|
|
<?php
|
2014-11-26 15:00:36 +00:00
|
|
|
|
2015-04-19 08:52:39 +01:00
|
|
|
/*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2015-01-02 00:18:19 +00:00
|
|
|
namespace CachetHQ\Cachet\Http\Controllers\Api;
|
2014-11-26 15:00:36 +00:00
|
|
|
|
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;
|
2014-11-26 15:00:36 +00:00
|
|
|
|
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
|
|
|
|
*/
|
2014-12-01 12:03:32 +00:00
|
|
|
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)
|
|
|
|
{
|
2014-12-01 12:03:32 +00:00
|
|
|
$this->incident = $incident;
|
2014-11-27 16:36:24 +00:00
|
|
|
}
|
2014-11-26 15:00:36 +00:00
|
|
|
|
2014-11-27 16:36:24 +00:00
|
|
|
/**
|
2014-12-30 18:19:22 +00:00
|
|
|
* Get all incidents.
|
2014-11-27 16:36:24 +00:00
|
|
|
*
|
|
|
|
* @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-27 16:36:24 +00:00
|
|
|
}
|
2014-11-26 16:08:47 +00:00
|
|
|
|
2014-11-27 16:36:24 +00:00
|
|
|
/**
|
2014-12-30 18:19:22 +00:00
|
|
|
* Get a single incident.
|
2014-11-27 16:36:24 +00:00
|
|
|
*
|
|
|
|
* @param int $id
|
|
|
|
*
|
2015-01-02 00:18:19 +00:00
|
|
|
* @return \CachetHQ\Cachet\Models\Incident
|
2014-11-27 16:36:24 +00:00
|
|
|
*/
|
2014-12-20 21:20:17 +00:00
|
|
|
public function getIncident($id)
|
|
|
|
{
|
2014-12-01 12:03:32 +00:00
|
|
|
return $this->incident->findOrFail($id);
|
2014-11-27 16:36:24 +00:00
|
|
|
}
|
2014-11-26 16:08:47 +00:00
|
|
|
|
2014-11-27 16:36:24 +00:00
|
|
|
/**
|
2014-12-30 18:19:22 +00:00
|
|
|
* Create a new incident.
|
2014-11-27 16:36:24 +00:00
|
|
|
*
|
2015-01-02 00:18:19 +00:00
|
|
|
* @return \CachetHQ\Cachet\Models\Incident
|
2014-11-27 16:36:24 +00:00
|
|
|
*/
|
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-11-27 16:36:24 +00:00
|
|
|
}
|
2014-11-26 15:00:36 +00:00
|
|
|
|
2014-11-27 16:36:24 +00:00
|
|
|
/**
|
2014-12-30 18:19:22 +00:00
|
|
|
* Update an existing incident.
|
2014-11-27 16:36:24 +00:00
|
|
|
*
|
|
|
|
* @param int $id
|
|
|
|
*
|
2015-01-02 00:18:19 +00:00
|
|
|
* @return \CachetHQ\Cachet\Models\Incident
|
2014-11-27 16:36:24 +00:00
|
|
|
*/
|
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());
|
2014-11-27 16:36:24 +00:00
|
|
|
}
|
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
|
|
|
}
|
2014-11-27 22:08:28 +00:00
|
|
|
}
|