|
@@ -3,6 +3,7 @@
|
|
|
use Silex\Application;
|
|
|
use Symfony\Component\HttpFoundation\Request;
|
|
|
use Symfony\Component\HttpFoundation\Response;
|
|
|
+use Symfony\Component\HttpKernel\HttpKernelInterface;
|
|
|
|
|
|
const BACKBONE = '/client/index.html';
|
|
|
|
|
@@ -20,12 +21,22 @@ $app->get('/todos/{id}', function (Application $app, int $id) {
|
|
|
return $app->json($todo);
|
|
|
});
|
|
|
$app->put('/todos/{id}', function (Application $app, Request $request, int $id) {
|
|
|
+ $sub = Request::create('/todos', 'POST', [], [], [], [], $request->getContent());
|
|
|
+ return $app->handle($sub, HttpKernelInterface::SUB_REQUEST);
|
|
|
+});
|
|
|
+$app->post('/todos', function (Application $app, Request $request) {
|
|
|
/** @var \Model $model */
|
|
|
$model = $app['model'];
|
|
|
$data = json_decode($request->getContent(), true);
|
|
|
$created = $model->save($data);
|
|
|
return new Response('Saved', $created ? Response::HTTP_CREATED : Response::HTTP_OK);
|
|
|
+})->value('id', NULL);
|
|
|
+$app->delete('/todos/{id}', function (Application $app, int $id) {
|
|
|
+ /** @var \Model $model */
|
|
|
+ $model = $app['model'];
|
|
|
+ $deleted = $model->delete($id);
|
|
|
+ return new Response($deleted ? 'Deleted' : 'It was not there anyway', Response::HTTP_OK);
|
|
|
});
|
|
|
$app->match('{url}', function ($url) {
|
|
|
- var_dump($url);
|
|
|
+ return new Response('Nothing to do', Response::HTTP_OK);
|
|
|
});
|