diff options
Diffstat (limited to 'src/Wallabag/ApiBundle')
-rw-r--r-- | src/Wallabag/ApiBundle/Controller/EntryRestController.php | 21 |
1 files changed, 17 insertions, 4 deletions
diff --git a/src/Wallabag/ApiBundle/Controller/EntryRestController.php b/src/Wallabag/ApiBundle/Controller/EntryRestController.php index 16d8a40b..5c850091 100644 --- a/src/Wallabag/ApiBundle/Controller/EntryRestController.php +++ b/src/Wallabag/ApiBundle/Controller/EntryRestController.php | |||
@@ -568,18 +568,31 @@ class EntryRestController extends WallabagRestController | |||
568 | * @ApiDoc( | 568 | * @ApiDoc( |
569 | * requirements={ | 569 | * requirements={ |
570 | * {"name"="entry", "dataType"="integer", "requirement"="\w+", "description"="The entry ID"} | 570 | * {"name"="entry", "dataType"="integer", "requirement"="\w+", "description"="The entry ID"} |
571 | * }, | ||
572 | * parameters={ | ||
573 | * {"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"}, | ||
571 | * } | 574 | * } |
572 | * ) | 575 | * ) |
573 | * | 576 | * |
574 | * @return JsonResponse | 577 | * @return JsonResponse |
575 | */ | 578 | */ |
576 | public function deleteEntriesAction(Entry $entry) | 579 | public function deleteEntriesAction(Entry $entry, Request $request) |
577 | { | 580 | { |
581 | $expect = $request->query->get('expect', 'entry'); | ||
582 | if (!\in_array($expect, ['id', 'entry'], true)) { | ||
583 | throw new BadRequestHttpException(sprintf("expect: 'id' or 'entry' expected, %s given", $expect)); | ||
584 | } | ||
578 | $this->validateAuthentication(); | 585 | $this->validateAuthentication(); |
579 | $this->validateUserAccess($entry->getUser()->getId()); | 586 | $this->validateUserAccess($entry->getUser()->getId()); |
580 | 587 | ||
581 | // We copy $entry to keep id in returned object | 588 | $response = $this->sendResponse([ |
582 | $e = $entry; | 589 | 'id' => $entry->getId(), |
590 | ]); | ||
591 | // We clone $entry to keep id in returned object | ||
592 | if ('entry' === $expect) { | ||
593 | $e = clone $entry; | ||
594 | $response = $this->sendResponse($e); | ||
595 | } | ||
583 | 596 | ||
584 | $em = $this->getDoctrine()->getManager(); | 597 | $em = $this->getDoctrine()->getManager(); |
585 | $em->remove($entry); | 598 | $em->remove($entry); |
@@ -588,7 +601,7 @@ class EntryRestController extends WallabagRestController | |||
588 | // entry deleted, dispatch event about it! | 601 | // entry deleted, dispatch event about it! |
589 | $this->get('event_dispatcher')->dispatch(EntryDeletedEvent::NAME, new EntryDeletedEvent($entry)); | 602 | $this->get('event_dispatcher')->dispatch(EntryDeletedEvent::NAME, new EntryDeletedEvent($entry)); |
590 | 603 | ||
591 | return $this->sendResponse($e); | 604 | return $response; |
592 | } | 605 | } |
593 | 606 | ||
594 | /** | 607 | /** |