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:
@@ -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}
|
||||
|
||||
Reference in New Issue
Block a user