Files
api/services/nginx/app/objects/motorapi_lookups_o.php
T
Jepp9350 8702b41777 Add MotorAPI integration and Economic products support
Implemented MotorAPI lookup functionality with proper validation and logging. Added Economic products endpoint for fetching product details. Enhanced route parameter validation with length constraints and improved response handling for objects.
2025-02-18 12:34:26 +01:00

82 lines
2.3 KiB
PHP

<?php
namespace objects;
use classes\db;
use classes\object_property;
use Exception;
use traits\db_object_t;
class motorapi_lookups_o extends db
{
use db_object_t;
public object_property $license_plate;
public object_property $result;
public object_property $endpoint;
public object_property $created_at;
public function structure(): void
{
$this->setTable('motorapi_lookups');
}
/**
* Add a motorapi lookup
* @param string $license_plate
* @param string $result
* @param string $endpoint
* @return void
* @throws Exception If the object was not created successfully
*/
public function add(string $license_plate, string $result, string $endpoint): void
{
$tmp_id = self::add_object([
'license_plate' => $license_plate,
'result' => $result,
'endpoint' => $endpoint
]);
$this->id = $tmp_id;
self::getObjectProperties();
self::objectChanged();
}
public function getObjectProperties(): void
{
$this->license_plate = new object_property($this->table, $this->id, 'license_plate', 'string', false);
$this->result = new object_property($this->table, $this->id, 'result', 'string', false);
$this->endpoint = new object_property($this->table, $this->id, 'endpoint', 'string', false);
$this->created_at = new object_property($this->table, $this->id, 'created_at', 'datetime', false);
}
public function objectChanged(): void
{
//TODO: Add cache invalidation
}
/**
* Get the amount of motorapi lookups created today
* @return int
*/
public function getTodayCount(): int
{
global /** @var db $db */
$db;
$sql = 'SELECT COUNT(*) FROM ' . $this->table . ' WHERE DATE(created_at) = CURDATE()';
$result = $db->query($sql);
return (int)$result->fetch_row()[0];
}
public function asArray(): array
{
return [
'id' => (int)$this->id,
'license_plate' => (string)$this->license_plate->value(),
'result' => (string)$this->result->value(),
'endpoint' => (string)$this->endpoint->value(),
'created_at' => (string)$this->created_at->value(),
];
}
}