From e32e0c43136c441301c7587819798809ffb75952 Mon Sep 17 00:00:00 2001 From: Thibault Debatty <t.debatty@cylab.be> Date: Sat, 10 Feb 2024 09:28:47 +0100 Subject: [PATCH] json : encode status color and last record time --- app/Server.php | 6 +++++- app/Status.php | 3 ++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/app/Server.php b/app/Server.php index a08618f..7d65a3a 100644 --- a/app/Server.php +++ b/app/Server.php @@ -39,7 +39,7 @@ class Server extends Model // add attributes when serializing to json // https://laravel.com/docs/8.x/eloquent-serialization#appending-values-to-json - protected $appends = ['url', 'status', 'failing_sensors']; + protected $appends = ['url', 'status', 'failing_sensors', 'last_record_time']; public function getUrlAttribute() : string { @@ -62,6 +62,10 @@ class Server extends Model return $failing_sensors; } + public function getLastRecordTime() : int + { + return $this->info()->lastRecordTime()->timestamp; + } /** diff --git a/app/Status.php b/app/Status.php index 7d9fee7..cd4732b 100644 --- a/app/Status.php +++ b/app/Status.php @@ -37,7 +37,8 @@ class Status { return [ "code" => $this->code, - "name" => $this->__toString()]; + "name" => $this->__toString(), + "color" => $this->color()]; } public function code() : int -- GitLab