Refactor database operations and enhance routes for consistency

Refactored database methods to improve code readability, reusability, and error handling. Introduced input validation helper functions and parsing capabilities for objects with optional callbacks. Added new routes for handling categories and improved product-related functionality to align with the new architecture.
This commit is contained in:
Jepp9350
2025-02-12 16:39:52 +01:00
parent c240bbd94f
commit 7525a89154
11 changed files with 375 additions and 66 deletions
+27
View File
@@ -20,6 +20,33 @@ trait route_t
// Add the routes here
}
public function requireParameters(array $parameters): void
{
global $response;
$missing_parameters = [];
// Check if all required parameters are set
foreach ( $parameters as $parameter ) {
if (!$response->getRequestParameter($parameter)) {
$missing_parameters[] = $parameter;
}
}
if (count($missing_parameters) > 0) {
$response->error('Missing required parameters: ' . implode(', ', $missing_parameters), 400);
}
}
public function isParametersSet(array $parameters): bool
{
global $response;
// Check if all required parameters are set
foreach ( $parameters as $parameter ) {
if (!$response->isRequestParameterSet($parameter)) {
return false;
}
}
return true;
}
/**
* GET route
* @param string $route Example: /home, /home/{id}