diff --git a/services/nginx/app/objects/plate_scans_o.php b/services/nginx/app/objects/plate_scans_o.php index 61da9b37..92dfa833 100644 --- a/services/nginx/app/objects/plate_scans_o.php +++ b/services/nginx/app/objects/plate_scans_o.php @@ -12,6 +12,7 @@ class plate_scans_o extends db public object_property $plate_scanner_id; public object_property $plate; + public object_property $bay_id; public function structure(): void { @@ -40,14 +41,19 @@ class plate_scans_o extends db { $this->plate_scanner_id = new object_property($this->table, $this->id, 'plate_scanner_id', 'int'); $this->plate = new object_property($this->table, $this->id, 'plate', 'string'); + $this->bay_id = new object_property($this->table, $this->id, 'bay_id', 'string'); } - public function add(int $plate_scanner_id, string $plate): void + public function add(int $plate_scanner_id, string $plate, string $bayId = null): void { global $db, $response; try { // Avoid SQL injection $plate = $db->escape_string($plate); + // If the bayId is set, validate it + if ($bayId !== null) { + $bayId = $db->escape_string($bayId); + } // Get the department id from the plate scanner id $sql = "SELECT department_id FROM plate_scanners WHERE id = $plate_scanner_id"; $result = $db->query($sql); @@ -59,9 +65,12 @@ class plate_scans_o extends db // Get the id of the new record $this->id = $db->insert_id(); - // Set the values of the object properties $this->getObjectProperties(); + // Set the bayId if provided + if ($bayId !== null) { + $this->bay_id->set((string)$bayId); + } } catch (\Exception $e) { $response->error($e->getMessage()); } diff --git a/services/nginx/app/routes/plateScansRoute.php b/services/nginx/app/routes/plateScansRoute.php index 752c67d0..1d7ab59d 100644 --- a/services/nginx/app/routes/plateScansRoute.php +++ b/services/nginx/app/routes/plateScansRoute.php @@ -23,6 +23,20 @@ class plateScansRoute $this->requirePlateScannerAuth(); // Get the plate scanner object $plate_scanner = (new authentication())->get_plate_scanner(); + /** + * Define the optional request body parameters + * - plate: The license plate to scan (string, required) + * - bayId: The wash bay id (int, optional) - XLVASK lanes only + */ + $bayId = null; + // Validate the bayId if set + $bayIdParameterKey = 'bay_id'; + if (self::isParametersSet([$bayIdParameterKey])) { + $bayId = self::getParameter($bayIdParameterKey); + self::requireType($bayId, self::type_string()); + self::requireMinLength($bayIdParameterKey, 1); + self::requireMaxLength($bayIdParameterKey, 255); + } // Get the post data $data = json_decode(file_get_contents('php://input'), true); // Check if the required fields are set @@ -30,11 +44,11 @@ class plateScansRoute $response->error('Missing required body parameter plate', 400); } // Add the number plate scanner - (new plate_scans_o())->add($plate_scanner->id, $data['plate']); + (new plate_scans_o())->add($plate_scanner->id, $data['plate'], $bayId); // Log the incident (new logs_o())->add('numberplatescans', $plate_scanner->department_id->value(), 1, 0, 'ADD_NUMBER_PLATE_SCANS', 'Successfully added a number plate scan: ' . $data['plate']); // Return a success message - $response->success(['message' => 'License plate scan recorded.', 'plate' => $data['plate'], 'scanner' => $plate_scanner->name->value()], 201); + $response->success(['message' => 'License plate scan recorded.', 'plate' => $data['plate'], 'scanner' => $plate_scanner->name->value(), ['bay_id' => $bayId]], 201); }); $this->post('/numberplatescans/department', function () {