Added ReportIncidentCommand

This commit is contained in:
James Brooks
2015-08-31 11:32:39 +01:00
parent 37d7908606
commit 082062fa1b
8 changed files with 115 additions and 58 deletions

View File

@@ -12,7 +12,7 @@
namespace CachetHQ\Cachet\Http\Controllers\Api;
use CachetHQ\Cachet\Commands\Incident\RemoveIncidentCommand;
use CachetHQ\Cachet\Events\Incident\IncidentWasReportedEvent;
use CachetHQ\Cachet\Commands\Incident\ReportIncidentCommand;
use CachetHQ\Cachet\Models\Incident;
use Exception;
use GrahamCampbell\Binput\Facades\Binput;
@@ -63,30 +63,20 @@ class IncidentController extends AbstractApiController
*/
public function postIncidents(Guard $auth)
{
$incidentData = array_filter(Binput::only([
'name',
'message',
'status',
'component_id',
'notify',
'visible',
]));
// Default visibility is 1.
if (!array_has($incidentData, 'visible')) {
$incidentData['visible'] = 1;
}
try {
$incident = Incident::create($incidentData);
$incident = $this->dispatch(new ReportIncidentCommand(
Binput::get('name'),
Binput::get('status'),
Binput::get('message'),
Binput::get('visible', true),
Binput::get('component_id'),
Binput::get('component_status'),
Binput::get('notify', true)
));
} catch (Exception $e) {
throw new BadRequestHttpException();
}
if (array_get($incidentData, 'notify') && subscribers_enabled()) {
event(new IncidentWasReportedEvent($incident));
}
return $this->item($incident);
}