aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/Wallabag/ApiBundle/Controller
diff options
context:
space:
mode:
Diffstat (limited to 'src/Wallabag/ApiBundle/Controller')
-rw-r--r--src/Wallabag/ApiBundle/Controller/EntryRestController.php103
-rw-r--r--src/Wallabag/ApiBundle/Controller/TagRestController.php4
2 files changed, 105 insertions, 2 deletions
diff --git a/src/Wallabag/ApiBundle/Controller/EntryRestController.php b/src/Wallabag/ApiBundle/Controller/EntryRestController.php
index af5f7603..7590efbb 100644
--- a/src/Wallabag/ApiBundle/Controller/EntryRestController.php
+++ b/src/Wallabag/ApiBundle/Controller/EntryRestController.php
@@ -438,4 +438,107 @@ class EntryRestController extends WallabagRestController
438 438
439 return (new JsonResponse())->setJson($json); 439 return (new JsonResponse())->setJson($json);
440 } 440 }
441
442 /**
443 * Handles an entries list delete tags from them.
444 *
445 * @ApiDoc(
446 * parameters={
447 * {"name"="list", "dataType"="string", "required"=true, "format"="A JSON array of urls [{'url': 'http://...','tags': 'tag1, tag2'}, {'url': 'http://...','tags': 'tag1, tag2'}]", "description"="Urls (as an array) to handle."}
448 * }
449 * )
450 *
451 * @return JsonResponse
452 */
453 public function deleteEntriesTagsListAction(Request $request)
454 {
455 $this->validateAuthentication();
456
457 $list = json_decode($request->query->get('list', []));
458 $results = [];
459
460 // handle multiple urls
461 if (!empty($list)) {
462 foreach ($list as $key => $element) {
463 $entry = $this->get('wallabag_core.entry_repository')->findByUrlAndUserId(
464 $element->url,
465 $this->getUser()->getId()
466 );
467
468 $results[$key]['url'] = $element->url;
469 $results[$key]['entry'] = $entry instanceof Entry ? $entry->getId() : false;
470
471 $tags = $element->tags;
472
473 if (false !== $entry && !(empty($tags))) {
474 $tags = explode(',', $tags);
475 foreach ($tags as $label) {
476 $label = trim($label);
477
478 $tag = $this->getDoctrine()
479 ->getRepository('WallabagCoreBundle:Tag')
480 ->findOneByLabel($label);
481
482 if (false !== $tag) {
483 $entry->removeTag($tag);
484 }
485 }
486
487 $em = $this->getDoctrine()->getManager();
488 $em->persist($entry);
489 $em->flush();
490 }
491 }
492 }
493
494 $json = $this->get('serializer')->serialize($results, 'json');
495
496 return (new JsonResponse())->setJson($json);
497 }
498
499 /**
500 * Handles an entries list and add tags to them.
501 *
502 * @ApiDoc(
503 * parameters={
504 * {"name"="list", "dataType"="string", "required"=true, "format"="A JSON array of urls [{'url': 'http://...','tags': 'tag1, tag2'}, {'url': 'http://...','tags': 'tag1, tag2'}]", "description"="Urls (as an array) to handle."}
505 * }
506 * )
507 *
508 * @return JsonResponse
509 */
510 public function postEntriesTagsListAction(Request $request)
511 {
512 $this->validateAuthentication();
513
514 $list = json_decode($request->query->get('list', []));
515 $results = [];
516
517 // handle multiple urls
518 if (!empty($list)) {
519 foreach ($list as $key => $element) {
520 $entry = $this->get('wallabag_core.entry_repository')->findByUrlAndUserId(
521 $element->url,
522 $this->getUser()->getId()
523 );
524
525 $results[$key]['url'] = $element->url;
526 $results[$key]['entry'] = $entry instanceof Entry ? $entry->getId() : false;
527
528 $tags = $element->tags;
529
530 if (false !== $entry && !(empty($tags))) {
531 $this->get('wallabag_core.content_proxy')->assignTagsToEntry($entry, $tags);
532
533 $em = $this->getDoctrine()->getManager();
534 $em->persist($entry);
535 $em->flush();
536 }
537 }
538 }
539
540 $json = $this->get('serializer')->serialize($results, 'json');
541
542 return (new JsonResponse())->setJson($json);
543 }
441} 544}
diff --git a/src/Wallabag/ApiBundle/Controller/TagRestController.php b/src/Wallabag/ApiBundle/Controller/TagRestController.php
index bc6d4e64..47298d7e 100644
--- a/src/Wallabag/ApiBundle/Controller/TagRestController.php
+++ b/src/Wallabag/ApiBundle/Controller/TagRestController.php
@@ -31,7 +31,7 @@ class TagRestController extends WallabagRestController
31 } 31 }
32 32
33 /** 33 /**
34 * Permanently remove one tag from **every** entry. 34 * Permanently remove one tag from **every** entry by passing the Tag label.
35 * 35 *
36 * @ApiDoc( 36 * @ApiDoc(
37 * requirements={ 37 * requirements={
@@ -106,7 +106,7 @@ class TagRestController extends WallabagRestController
106 } 106 }
107 107
108 /** 108 /**
109 * Permanently remove one tag from **every** entry. 109 * Permanently remove one tag from **every** entry by passing the Tag ID.
110 * 110 *
111 * @ApiDoc( 111 * @ApiDoc(
112 * requirements={ 112 * requirements={