Allow updating incidents from the API
This commit is contained in:
@@ -88,6 +88,32 @@
|
||||
public function postIncidents() {
|
||||
$incident = new Incident(Input::all());
|
||||
$incident->user_id = $this->auth->user()->id;
|
||||
return $this->saveIncident($incident);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update an existing incident
|
||||
*
|
||||
* @param int $id
|
||||
*
|
||||
* @return Incident
|
||||
*/
|
||||
public function putIncident($id) {
|
||||
$incident = $this->getIncident($id);
|
||||
|
||||
$incident->fill(Input::all());
|
||||
|
||||
return $this->saveIncident($incident);
|
||||
}
|
||||
|
||||
/**
|
||||
* Function for saving the incident, and returning appropriate error codes
|
||||
*
|
||||
* @param Incident $incident
|
||||
*
|
||||
* @return Incident
|
||||
*/
|
||||
private function saveIncident($incident) {
|
||||
if ($incident->isValid()) {
|
||||
try {
|
||||
$component = $incident->parent;
|
||||
@@ -104,4 +130,5 @@
|
||||
App::abort(404, $incident->getErrors()->first());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
'status' => 'required|integer'
|
||||
];
|
||||
|
||||
protected $fillable = ['user_id', 'name', 'description', 'status'];
|
||||
protected $fillable = ['name', 'description', 'status'];
|
||||
|
||||
/**
|
||||
* Lookup all of the incidents reported on the component.
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
'message' => 'required',
|
||||
];
|
||||
|
||||
protected $fillable = ['user_id', 'component', 'name', 'status', 'message'];
|
||||
protected $fillable = ['component', 'name', 'status', 'message'];
|
||||
|
||||
/**
|
||||
* An incident belongs to a component.
|
||||
|
||||
@@ -11,6 +11,8 @@
|
||||
Route::group(['protected' => true], function() {
|
||||
Route::post('components', 'ApiController@postComponents');
|
||||
Route::post('incidents', 'ApiController@postIncidents');
|
||||
|
||||
Route::put('incidents/{id}', 'ApiController@putIncident');
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user