Allow updating incidents from the API

This commit is contained in:
manavo
2014-11-25 12:40:12 +00:00
parent 325ed033ba
commit a4d3928916
4 changed files with 31 additions and 2 deletions

View File

@@ -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());
}
}
}

View File

@@ -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.

View File

@@ -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.

View File

@@ -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');
});
});