aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/Wallabag
diff options
context:
space:
mode:
authorKevin Decherf <kevin@kdecherf.com>2019-02-17 15:30:42 +0100
committerKevin Decherf <kevin@kdecherf.com>2019-02-20 15:57:50 +0100
commit508302042f96ce771a36f0114acb0b3a89c18880 (patch)
treef599aafa60d81b1dbf473fc7d586abc84a18d1cf /src/Wallabag
parent4e0ed3368d2bdc2fa0d330e58902e792a896be06 (diff)
downloadwallabag-508302042f96ce771a36f0114acb0b3a89c18880.tar.gz
wallabag-508302042f96ce771a36f0114acb0b3a89c18880.tar.zst
wallabag-508302042f96ce771a36f0114acb0b3a89c18880.zip
EntryRestController: add support of expect parameter to delete action
The expect parameter enables an application to request the whole entry or only the id when requesting its deletion. `expects` defaults to `entry` to prevent any API breakage. Fixes #3711 Signed-off-by: Kevin Decherf <kevin@kdecherf.com>
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 /**