diff --git a/app/controllers/api.php b/app/controllers/api.php index 6e02ea0..a7a35a3 100644 --- a/app/controllers/api.php +++ b/app/controllers/api.php @@ -14,11 +14,10 @@ $api->before(function (Request $request) { $api->get('/', function () { return 'API home page'; }); $api->get('/entries', function () use ($app) { - $entries = $app['entry_api']->getEntries(); + $entries = $app['entry_api']->getEntries('unread'); return $app->json($entries, 200); }); - $api->post('/entries', function (Request $request) use ($app) { $url = $request->request->get('url'); @@ -27,6 +26,11 @@ $api->post('/entries', function (Request $request) use ($app) { return $app->json($entry, 201); }); +$api->get('/archives', function () use ($app) { + $entries = $app['entry_api']->getEntries('read'); + return $app->json($entries, 200); +}); + $api->get('/get', function (Request $request) use ($app) { $id = $request->request->get('id'); @@ -43,4 +47,12 @@ $api->get('/mark-read', function (Request $request) use ($app) { return $app->json($entry, 201); }); +$api->get('/mark-unread', function (Request $request) use ($app) { + $id = $request->request->get('id'); + + $entry = $app['entry_api']->markAsUnread($id); + + return $app->json($entry, 201); +}); + return $api; diff --git a/app/controllers/front.php b/app/controllers/front.php index cd9fe3c..18fbfc9 100644 --- a/app/controllers/front.php +++ b/app/controllers/front.php @@ -23,10 +23,22 @@ $front->get('/mark-read/{id}', function (Request $request, $id) use ($app) { $entry = $app['entry_api']->markAsRead($id); - return $app->redirect('/view/' . $id); + $referer = $request->headers->get('referer'); + + return $app->redirect($referer); }) ->bind('mark_entry_read'); +$front->get('/mark-unread/{id}', function (Request $request, $id) use ($app) { + + $entry = $app['entry_api']->markAsUnread($id); + + $referer = $request->headers->get('referer'); + + return $app->redirect($referer); +}) +->bind('mark_entry_unread'); + $front->match('/add', function (Request $request) use ($app) { $data = array('url');