From f9ceb70e500d9c149c617f63b3ae01b2f287edbb Mon Sep 17 00:00:00 2001 From: James Brooks Date: Tue, 25 Nov 2014 09:40:54 +0000 Subject: [PATCH] API for returning incidents on a component, including incident_count --- app/controllers/ApiController.php | 5 +++++ app/routes/api.php | 1 + app/transformers/ComponentTransformer.php | 1 + 3 files changed, 7 insertions(+) diff --git a/app/controllers/ApiController.php b/app/controllers/ApiController.php index c47722d07..31cffb277 100644 --- a/app/controllers/ApiController.php +++ b/app/controllers/ApiController.php @@ -14,4 +14,9 @@ } } + public function getComponentIncidents($id) { + $component = $this->getComponent($id); + return $component->incidents; + } + } diff --git a/app/routes/api.php b/app/routes/api.php index 4059f2b24..dda32400f 100644 --- a/app/routes/api.php +++ b/app/routes/api.php @@ -4,5 +4,6 @@ Route::get('components', 'ApiController@getComponents'); Route::get('components/{id}', 'ApiController@getComponent'); + Route::get('components/{id}/incidents', 'ApiController@getComponentIncidents'); }); diff --git a/app/transformers/ComponentTransformer.php b/app/transformers/ComponentTransformer.php index d3eade610..c586998ae 100644 --- a/app/transformers/ComponentTransformer.php +++ b/app/transformers/ComponentTransformer.php @@ -8,6 +8,7 @@ 'description' => $component->description, 'status_id' => (int) $component->status, 'status' => $component->getHumanStatusAttribute(), + 'incident_count' => $component->incidents()->count() ]; }