Delete tag or tags by label

Tests not included
This commit is contained in:
Thomas Citharel 2016-06-25 18:37:41 +02:00 committed by Jeremy Benoist
parent e71cef0bb8
commit 4da01f492b
No known key found for this signature in database
GPG Key ID: BCA73962457ACC3C
2 changed files with 74 additions and 0 deletions

View File

@ -352,6 +352,67 @@ class WallabagRestController extends FOSRestController
return $this->renderJsonResponse($json);
}
/**
* Permanently remove one tag from **every** entry.
*
* @ApiDoc(
* requirements={
* {"name"="tag", "dataType"="string", "requirement"="\w+", "description"="The tag as a string"}
* }
* )
*
* @return Response
*/
public function deleteTagLabelAction(Request $request)
{
$this->validateAuthentication();
$label = $request->query->get('tag','');
$tag = $this->getDoctrine()->getRepository('WallabagCoreBundle:Tag')->findOneByLabel($label);
$this->getDoctrine()
->getRepository('WallabagCoreBundle:Entry')
->removeTag($this->getUser()->getId(), $tag);
$json = $this->get('serializer')->serialize($tag, 'json');
return $this->renderJsonResponse($json);
}
/**
* Permanently remove some tags from **every** entry.
*
* @ApiDoc(
* requirements={
* {"name"="tags", "dataType"="string", "required"=true, "format"="tag1,tag2", "description"="The tags as strings"}
* }
* )
*
* @return Response
*/
public function deleteTagsLabelAction(Request $request)
{
$this->validateAuthentication();
$tagsLabels = $request->query->get('tags', '');
$tags = array();
foreach (explode(',', $tagsLabels) as $tagLabel) {
$tagEntity = $this->getDoctrine()->getRepository('WallabagCoreBundle:Tag')->findOneByLabel($tagLabel);
$tags[] = $tagEntity;
}
$this->getDoctrine()
->getRepository('WallabagCoreBundle:Entry')
->removeTags($this->getUser()->getId(), $tags);
$json = $this->get('serializer')->serialize($tags, 'json');
return $this->renderJsonResponse($json);
}
/**
* Retrieve version number.
*

View File

@ -222,6 +222,19 @@ class EntryRepository extends EntityRepository
$this->getEntityManager()->flush();
}
/**
* Remove tags from all user entries
*
* @param int $userId
* @param Array<Tag> $tags
*/
public function removeTags($userId, $tags) {
foreach ($tags as $tag) {
$this->removeTag($userId, $tag);
}
}
/**
* Find all entries that are attached to a give tag id.
*