diff --git a/app/controllers/ApiController.php b/app/controllers/ApiController.php index 31cffb27..98960ad2 100644 --- a/app/controllers/ApiController.php +++ b/app/controllers/ApiController.php @@ -19,4 +19,16 @@ 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'); + } + } + } diff --git a/app/models/Component.php b/app/models/Component.php index 9c429b8e..337cf371 100644 --- a/app/models/Component.php +++ b/app/models/Component.php @@ -20,7 +20,7 @@ /** * Get the transformer instance. * - * @return mixed + * @return ComponentTransformer */ public function getTransformer() { return new ComponentTransformer(); diff --git a/app/models/Incident.php b/app/models/Incident.php index a92a5b12..8f1ac425 100644 --- a/app/models/Incident.php +++ b/app/models/Incident.php @@ -1,6 +1,6 @@ $component->description, 'status_id' => (int) $component->status, '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, ]; } - } diff --git a/app/transformers/IncidentTransformer.php b/app/transformers/IncidentTransformer.php new file mode 100644 index 00000000..ab1f6b5f --- /dev/null +++ b/app/transformers/IncidentTransformer.php @@ -0,0 +1,19 @@ +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, + ]; + } + }