aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/Wallabag
diff options
context:
space:
mode:
authorJérémy Benoist <j0k3r@users.noreply.github.com>2019-02-25 10:56:07 +0100
committerGitHub <noreply@github.com>2019-02-25 10:56:07 +0100
commit4de99d1ab161fc378e0f7cc121c60396f86bc577 (patch)
tree7495caff11c8183fb1aeed9abebf38c6a4a2207f /src/Wallabag
parentb1992b340e21b6846a1ec2ae6ddd7217f3b24fb5 (diff)
parent12a97c352275d81e9252ca4179de51180403eb6f (diff)
downloadwallabag-4de99d1ab161fc378e0f7cc121c60396f86bc577.tar.gz
wallabag-4de99d1ab161fc378e0f7cc121c60396f86bc577.tar.zst
wallabag-4de99d1ab161fc378e0f7cc121c60396f86bc577.zip
Merge pull request #3887 from wallabag/issue-3711
Add support of expect parameter to change return object when deleting entry
Diffstat (limited to 'src/Wallabag')
-rw-r--r--src/Wallabag/ApiBundle/Controller/EntryRestController.php21
1 files changed, 17 insertions, 4 deletions
diff --git a/src/Wallabag/ApiBundle/Controller/EntryRestController.php b/src/Wallabag/ApiBundle/Controller/EntryRestController.php
index b2bad406..33b75665 100644
--- a/src/Wallabag/ApiBundle/Controller/EntryRestController.php
+++ b/src/Wallabag/ApiBundle/Controller/EntryRestController.php
@@ -570,18 +570,31 @@ class EntryRestController extends WallabagRestController
570 * @ApiDoc( 570 * @ApiDoc(
571 * requirements={ 571 * requirements={
572 * {"name"="entry", "dataType"="integer", "requirement"="\w+", "description"="The entry ID"} 572 * {"name"="entry", "dataType"="integer", "requirement"="\w+", "description"="The entry ID"}
573 * },
574 * parameters={
575 * {"name"="expect", "dataType"="string", "required"=false, "format"="id or entry", "description"="Only returns the id instead of the deleted entry's full entity if 'id' is specified. Default to entry"},
573 * } 576 * }
574 * ) 577 * )
575 * 578 *
576 * @return JsonResponse 579 * @return JsonResponse
577 */ 580 */
578 public function deleteEntriesAction(Entry $entry) 581 public function deleteEntriesAction(Entry $entry, Request $request)
579 { 582 {
583 $expect = $request->query->get('expect', 'entry');
584 if (!\in_array($expect, ['id', 'entry'], true)) {
585 throw new BadRequestHttpException(sprintf("expect: 'id' or 'entry' expected, %s given", $expect));
586 }
580 $this->validateAuthentication(); 587 $this->validateAuthentication();
581 $this->validateUserAccess($entry->getUser()->getId()); 588 $this->validateUserAccess($entry->getUser()->getId());
582 589
583 // We copy $entry to keep id in returned object 590 $response = $this->sendResponse([
584 $e = $entry; 591 'id' => $entry->getId(),
592 ]);
593 // We clone $entry to keep id in returned object
594 if ('entry' === $expect) {
595 $e = clone $entry;
596 $response = $this->sendResponse($e);
597 }
585 598
586 $em = $this->getDoctrine()->getManager(); 599 $em = $this->getDoctrine()->getManager();
587 $em->remove($entry); 600 $em->remove($entry);
@@ -590,7 +603,7 @@ class EntryRestController extends WallabagRestController
590 // entry deleted, dispatch event about it! 603 // entry deleted, dispatch event about it!
591 $this->get('event_dispatcher')->dispatch(EntryDeletedEvent::NAME, new EntryDeletedEvent($entry)); 604 $this->get('event_dispatcher')->dispatch(EntryDeletedEvent::NAME, new EntryDeletedEvent($entry));
592 605
593 return $this->sendResponse($e); 606 return $response;
594 } 607 }
595 608
596 /** 609 /**