mirror of
https://github.com/ConnectedHumber/Air-Quality-Web
synced 2024-11-23 06:33:00 +00:00
Bugfix new device sensor list
This commit is contained in:
parent
a325940322
commit
7a489706bd
3 changed files with 22 additions and 9 deletions
|
@ -11,6 +11,8 @@ use AirQuality\Repositories\IMeasurementDataRepository;
|
|||
use AirQuality\Repositories\MariaDBMeasurementDataRepository;
|
||||
use AirQuality\Repositories\IMeasurementTypeRepository;
|
||||
use AirQuality\Repositories\MariaDBMeasurementTypeRepository;
|
||||
use AirQuality\Repositories\ISensorRepository;
|
||||
use AirQuality\Repositories\MariaDBSensorRepository;
|
||||
|
||||
use SBRL\PerformanceCounter;
|
||||
|
||||
|
@ -31,5 +33,6 @@ return [
|
|||
// Interfaces that need mapping to their implementations
|
||||
IDeviceRepository::class => DI\autowire(MariaDBDeviceRepository::class),
|
||||
IMeasurementDataRepository::class => DI\autowire(MariaDBMeasurementDataRepository::class),
|
||||
IMeasurementTypeRepository::class => DI\autowire(MariaDBMeasurementTypeRepository::class)
|
||||
IMeasurementTypeRepository::class => DI\autowire(MariaDBMeasurementTypeRepository::class),
|
||||
ISensorRepository::class => DI\autowire(MariaDBSensorRepository::class)
|
||||
];
|
||||
|
|
|
@ -4,6 +4,7 @@ namespace AirQuality\Actions;
|
|||
|
||||
use \SBRL\TomlConfig;
|
||||
use \AirQuality\Repositories\IDeviceRepository;
|
||||
use \AirQuality\Repositories\ISensorRepository;
|
||||
use \AirQuality\Repositories\IMeasurementTypeRepository;
|
||||
use \AirQuality\ApiResponseSender;
|
||||
|
||||
|
@ -19,6 +20,9 @@ class DeviceInfo implements IAction {
|
|||
/** @var IDeviceRepository */
|
||||
private $device_repo;
|
||||
|
||||
/** @var ISensorRepository */
|
||||
private $sensor_repo;
|
||||
|
||||
/** @var IMeasurementTypeRepository */
|
||||
private $type_repo;
|
||||
|
||||
|
@ -31,10 +35,12 @@ class DeviceInfo implements IAction {
|
|||
public function __construct(
|
||||
TomlConfig $in_settings,
|
||||
IDeviceRepository $in_device_repo,
|
||||
ISensorRepository $in_sensor_repo,
|
||||
ApiResponseSender $in_sender,
|
||||
\SBRL\PerformanceCounter $in_perfcounter) {
|
||||
$this->settings = $in_settings;
|
||||
$this->device_repo = $in_device_repo;
|
||||
$this->sensor_repo = $in_sensor_repo;
|
||||
$this->sender = $in_sender;
|
||||
$this->perfcounter = $in_perfcounter;
|
||||
|
||||
|
@ -52,7 +58,10 @@ class DeviceInfo implements IAction {
|
|||
// 2: Pull data from database
|
||||
$this->perfcounter->start("sql");
|
||||
$data = $this->device_repo->get_device_info_ext(
|
||||
$_GET["device-id"]
|
||||
intval($_GET["device-id"])
|
||||
);
|
||||
$data_sensor = $this->sensor_repo->get_device_sensors(
|
||||
intval($_GET["device-id"])
|
||||
);
|
||||
$this->perfcounter->end("sql");
|
||||
|
||||
|
@ -66,6 +75,7 @@ class DeviceInfo implements IAction {
|
|||
|
||||
// 3: Serialise data
|
||||
$this->perfcounter->start("encode");
|
||||
$data["sensors"] = $data_sensor;
|
||||
$response = json_encode($data);
|
||||
$this->perfcounter->end("encode");
|
||||
|
||||
|
|
|
@ -9,11 +9,11 @@ use Location\Distance\Vincenty;
|
|||
/**
|
||||
* Fetches device info from a MariaDB database.
|
||||
*/
|
||||
class MariaDBDeviceRepository implements ISensorRepository {
|
||||
class MariaDBSensorRepository implements ISensorRepository {
|
||||
public static $table_name = "sensors";
|
||||
public static $col_id = "id";
|
||||
public static $col_type = "Type";
|
||||
public static $col_descriptioon = "Description";
|
||||
public static $col_description = "Description";
|
||||
|
||||
public static $table_name_assoc = "device_sensors";
|
||||
public static $col_assoc_device_id = "device_id";
|
||||
|
@ -61,7 +61,7 @@ class MariaDBDeviceRepository implements ISensorRepository {
|
|||
"SELECT
|
||||
{$s("table_name")}.{$s("col_id")} AS id,
|
||||
{$s("table_name")}.{$s("col_type")} AS type,
|
||||
{$s("table_name")}.{$s("col_description")} AS description,
|
||||
{$s("table_name")}.{$s("col_description")} AS description
|
||||
FROM {$s("table_name")};", [
|
||||
|
||||
]
|
||||
|
@ -75,10 +75,10 @@ class MariaDBDeviceRepository implements ISensorRepository {
|
|||
"SELECT
|
||||
{$s("table_name")}.{$s("col_id")} AS id,
|
||||
{$s("table_name")}.{$s("col_type")} AS type,
|
||||
{$s("table_name")}.{$s("col_description")} AS description,
|
||||
FROM {$s("table_name")}
|
||||
JOIN {$s("table_name_assoc")} ON
|
||||
{$s("table_name_assoc")}.{$s("col_assoc_sensor_id")}
|
||||
{$s("table_name")}.{$s("col_description")} AS description
|
||||
FROM {$s("table_name_assoc")}
|
||||
JOIN {$s("table_name")}
|
||||
ON {$s("table_name")}.{$s("col_id")} = {$s("table_name_assoc")}.{$s("col_assoc_sensor_id")}
|
||||
WHERE {$s("table_name_assoc")}.{$s("col_assoc_device_id")} = :device_id;", [
|
||||
"device_id" => $device_id
|
||||
]
|
||||
|
|
Loading…
Reference in a new issue