1
0
mirror of https://github.com/moparisthebest/wallabag synced 2025-01-06 19:28:00 -05:00

[add] remove feature

This commit is contained in:
Nicolas Lœuillet 2014-01-14 15:22:38 +01:00
parent b9e8651815
commit 6fee53233e
7 changed files with 66 additions and 7 deletions

View File

@ -70,4 +70,12 @@ $api->get('/unstar', function (Request $request) use ($app) {
return $app->json($entry, 201);
});
$api->get('/remove', function (Request $request) use ($app) {
$id = $request->request->get('id');
$entry = $app['entry_api']->remove($id);
return $app->json($entry, 201);
});
return $api;

View File

@ -59,6 +59,16 @@ $front->get('/unstar/{id}', function (Request $request, $id) use ($app) {
})
->bind('unstar_entry');
$front->get('/remove/{id}', function (Request $request, $id) use ($app) {
$entry = $app['entry_api']->remove($id);
$referer = $request->headers->get('referer');
return $app->redirect($referer);
})
->bind('remove_entry');
$front->match('/add', function (Request $request) use ($app) {
$data = array('url');

View File

@ -4,7 +4,7 @@
<ul class="entry_options">
<li>{% if entry.status == "read" %}<a href="{{ path('mark_entry_unread', {'id': entry.id}) }}">{{ 'mark as unread'|trans }}</a>{% else %}<a href="{{ path('mark_entry_read', {'id': entry.id}) }}">{{ 'mark as read'|trans }}</a>{% endif %}</li>
<li><a href="#">{% if entry.bookmark == 1 %}<a href="{{ path('unstar_entry', {'id': entry.id}) }}">{{ 'unstar'|trans }}</a>{% else %}<a href="{{ path('star_entry', {'id': entry.id}) }}">{{ 'star'|trans }}</a>{% endif %}</a></li>
<li><a href="#">{{ 'delete'|trans }}</a></li>
<li><a href="{{ path('remove_entry', {'id': entry.id}) }}">{{ 'delete'|trans }}</a></li>
<li><a href="{{ entry.url }}">{{ 'view original'|trans }}</a></li>
</ul>
</li>

View File

@ -9,8 +9,8 @@
<h2>{{ entry.title }}</h2>
<ul class="entry_options">
<li>{% if entry.status == "read" %}<a href="{{ path('mark_entry_unread', {'id': entry.id}) }}">{{ 'mark as unread'|trans }}</a>{% else %}<a href="{{ path('mark_entry_read', {'id': entry.id}) }}">{{ 'mark as read'|trans }}</a>{% endif %}</li>
<li><a href="#">{% if entry.bookmark == 1 %}<a href="{{ path('unstar_entry', {'id': entry.id}) }}">{{ 'unstar'|trans }}</a>{% else %}<a href="{{ path('star_entry', {'id': entry.id}) }}">{{ 'star'|trans }}</a>{% endif %}</a></li>
<li><a href="#">{{ 'delete'|trans }}</a></li>
<li>{% if entry.bookmark == 1 %}<a href="{{ path('unstar_entry', {'id': entry.id}) }}">{{ 'unstar'|trans }}</a>{% else %}<a href="{{ path('star_entry', {'id': entry.id}) }}">{{ 'star'|trans }}</a>{% endif %}</li>
<li><a href="{{ path('remove_entry', {'id': entry.id}) }}">{{ 'delete'|trans }}</a></li>
<li><a href="{{ entry.url }}">{{ 'view original'|trans }}</a></li>
</ul>

View File

@ -39,6 +39,10 @@ class EntryApi
return $this->entryRepository->unstar($id);
}
public function remove($id) {
return $this->entryRepository->remove($id);
}
public function createEntryFromUrl($url) {
//TODO: Fetch all what we need, fill the title, content …

View File

@ -20,7 +20,7 @@ class EntryRepository
//TODO don't hardcode the user ;)
public function getBookmarks($userId = 1) {
$sql = "SELECT * FROM entries where user_id = ? AND bookmark = 1 ORDER BY id DESC";
$sql = "SELECT * FROM entries where user_id = ? AND bookmark = 1 and status <> 'removed' ORDER BY id DESC";
$entries = $this->db->fetchAll($sql, array($userId));
return $entries ? $entries : array();
@ -34,7 +34,7 @@ class EntryRepository
//TODO don't hardcode the user ;)
public function getEntryById($id, $userId = 1) {
$sql = "SELECT * FROM entries where id = ? AND user_id = ?";
$sql = "SELECT * FROM entries where id = ? AND user_id = ? AND status <> 'removed'";
$entry = $this->db->fetchAll($sql, array($id, $userId));
return $entry ? $entry : array();
@ -72,5 +72,13 @@ class EntryRepository
return $count;
}
//TODO don't hardcode the user ;)
public function remove($id, $userId = 1) {
$sql = "UPDATE entries SET status = 'removed' where id = ? AND user_id = ?";
$count = $this->db->executeUpdate($sql, array($id, $userId));
return $count;
}
}

View File

@ -195,6 +195,37 @@ class ApiTest extends PocheWebTestCase
$this->assertEquals('1', $client->getResponse()->getContent());
}
public function testRemove()
{
//Load some entries
Fixtures::loadEntries($this->app['db']);
$client = $this->createClient();
$crawler = $client->request(
'GET',
'/api/remove',
array(),
array(),
array('CONTENT_TYPE' => 'application/json'),
'{"id":"1"}'
);
$this->assertEquals($client->getResponse()->getStatusCode(), 201);
// Assert that the "Content-Type" header is "application/json"
$this->assertTrue(
$client->getResponse()->headers->contains(
'Content-Type',
'application/json'
)
);
$this->assertEquals('1', $client->getResponse()->getContent());
}
public function testPostEntries()
{
@ -222,7 +253,5 @@ class ApiTest extends PocheWebTestCase
);
$this->assertEquals($client->getResponse()->getContent(),'{"url":"http:\/\/perdu.com","title":"Vous Etes Perdu ?","content":"[unable to retrieve full-text content]"}');
}
}