mirror of
https://github.com/CachetHQ/Cachet.git
synced 2025-01-17 21:49:01 +01:00
commit
0c62f0534a
@ -19,4 +19,16 @@
|
|||||||
return $component->incidents;
|
return $component->incidents;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getIncidents() {
|
||||||
|
return Incident::all();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getIncident($id) {
|
||||||
|
if ($incident = Incident::find($id)) {
|
||||||
|
return $incident;
|
||||||
|
} else {
|
||||||
|
App::abort(404, 'Incident not found');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,7 @@
|
|||||||
/**
|
/**
|
||||||
* Get the transformer instance.
|
* Get the transformer instance.
|
||||||
*
|
*
|
||||||
* @return mixed
|
* @return ComponentTransformer
|
||||||
*/
|
*/
|
||||||
public function getTransformer() {
|
public function getTransformer() {
|
||||||
return new ComponentTransformer();
|
return new ComponentTransformer();
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
class Incident extends Eloquent {
|
class Incident extends Eloquent implements Dingo\Api\Transformer\TransformableInterface {
|
||||||
/**
|
/**
|
||||||
* An incident belongs to a component.
|
* An incident belongs to a component.
|
||||||
* @return Illuminate\Database\Eloquent\Relations\BelongsTo
|
* @return Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||||
@ -29,4 +29,13 @@
|
|||||||
case 4: return 'glyphicon-ok';
|
case 4: return 'glyphicon-ok';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the transformer instance.
|
||||||
|
*
|
||||||
|
* @return IncidentTransformer
|
||||||
|
*/
|
||||||
|
public function getTransformer() {
|
||||||
|
return new IncidentTransformer();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,5 +5,7 @@
|
|||||||
Route::get('components', 'ApiController@getComponents');
|
Route::get('components', 'ApiController@getComponents');
|
||||||
Route::get('components/{id}', 'ApiController@getComponent');
|
Route::get('components/{id}', 'ApiController@getComponent');
|
||||||
Route::get('components/{id}/incidents', 'ApiController@getComponentIncidents');
|
Route::get('components/{id}/incidents', 'ApiController@getComponentIncidents');
|
||||||
|
Route::get('incidents', 'ApiController@getIncidents');
|
||||||
|
Route::get('incidents/{id}', 'ApiController@getIncident');
|
||||||
|
|
||||||
});
|
});
|
||||||
|
@ -8,8 +8,9 @@
|
|||||||
'description' => $component->description,
|
'description' => $component->description,
|
||||||
'status_id' => (int) $component->status,
|
'status_id' => (int) $component->status,
|
||||||
'status' => $component->getHumanStatusAttribute(),
|
'status' => $component->getHumanStatusAttribute(),
|
||||||
'incident_count' => $component->incidents()->count()
|
'incident_count' => $component->incidents()->count(),
|
||||||
|
'created_at' => $component->created_at->timestamp,
|
||||||
|
'updated_at' => $component->updated_at->timestamp,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
19
app/transformers/IncidentTransformer.php
Normal file
19
app/transformers/IncidentTransformer.php
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
class IncidentTransformer extends \League\Fractal\TransformerAbstract {
|
||||||
|
public function transform(Incident $incident) {
|
||||||
|
$component = $incident->parent;
|
||||||
|
$transformer = $component->getTransformer();
|
||||||
|
|
||||||
|
return [
|
||||||
|
'id' => (int) $incident->id,
|
||||||
|
'name' => $incident->name,
|
||||||
|
'message' => $incident->message,
|
||||||
|
'status_id' => (int) $incident->status,
|
||||||
|
'status' => $incident->getHumanStatusAttribute(),
|
||||||
|
'component' => $transformer->transform($component),
|
||||||
|
'created_at' => $incident->created_at->timestamp,
|
||||||
|
'updated_at' => $incident->updated_at->timestamp,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user