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 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 | /** |