add route for creating a person, and post api

This commit is contained in:
2021-05-21 18:05:03 +02:00
parent 857298b8b8
commit ebe3bc5f7b
8 changed files with 246 additions and 19 deletions

View File

@@ -189,6 +189,20 @@ class CRUDRoutesLoader extends Loader
"or allow, at least, one method");
}
if ('_entity' === $name && \in_array(Request::METHOD_POST, $methods)) {
unset($methods[\array_search(Request::METHOD_POST, $methods)]);
$entityPostRoute = $this->createEntityPostRoute($name, $crudConfig, $action,
$controller, $requirements);
$collection->add("chill_api_single_{$crudConfig['name']}_{$name}_create",
$entityPostRoute);
}
if (count($methods) === 0) {
// the only method was POST,
// continue to next
continue;
}
$route = new Route($path, $defaults, $requirements);
$route->setMethods($methods);
@@ -197,4 +211,17 @@ class CRUDRoutesLoader extends Loader
return $collection;
}
private function createEntityPostRoute(string $name, $crudConfig, array $action, $controller, $requirements): Route
{
$localPath = $action['path'].'.{_format}';
$defaults = [
'_controller' => $controller.':'.($action['controller_action'] ?? 'entityPost')
];
$path = $crudConfig['base_path'].$localPath;
$route = new Route($path, $defaults, $requirements);
$route->setMethods([ Request::METHOD_POST ]);
return $route;
}
}