diff options
Diffstat (limited to 'src/Wallabag/ApiBundle')
-rw-r--r-- | src/Wallabag/ApiBundle/Controller/WallabagRestController.php | 87 |
1 files changed, 31 insertions, 56 deletions
diff --git a/src/Wallabag/ApiBundle/Controller/WallabagRestController.php b/src/Wallabag/ApiBundle/Controller/WallabagRestController.php index 07d0e1e9..e2e4924b 100644 --- a/src/Wallabag/ApiBundle/Controller/WallabagRestController.php +++ b/src/Wallabag/ApiBundle/Controller/WallabagRestController.php | |||
@@ -528,29 +528,26 @@ class WallabagRestController extends FOSRestController | |||
528 | * } | 528 | * } |
529 | * ) | 529 | * ) |
530 | * | 530 | * |
531 | * @return Response | 531 | * @param Entry $entry |
532 | * @return JsonResponse | ||
532 | */ | 533 | */ |
533 | public function getAnnotationsAction(Entry $entry) | 534 | public function getAnnotationsAction(Entry $entry) |
534 | { | 535 | { |
535 | $this->validateAuthentication(); | 536 | $this->validateAuthentication(); |
536 | 537 | ||
537 | $annotationRows = $this | 538 | $response = $this->forward('WallabagApiBundle:WallabagRest:getAnnotations', |
538 | ->getDoctrine() | 539 | [ |
539 | ->getRepository('WallabagAnnotationBundle:Annotation') | 540 | 'entry' => $entry |
540 | ->findAnnotationsByPageId($entry->getId(), $this->getUser()->getId()); | 541 | ]); |
541 | $total = count($annotationRows); | 542 | return $response; |
542 | $annotations = array('total' => $total, 'rows' => $annotationRows); | ||
543 | |||
544 | $json = $this->get('serializer')->serialize($annotations, 'json'); | ||
545 | |||
546 | return $this->renderJsonResponse($json); | ||
547 | } | 543 | } |
548 | 544 | ||
549 | /** | 545 | /** |
550 | * Creates a new annotation. | 546 | * Creates a new annotation. |
551 | * | 547 | * |
548 | * @param Request $request | ||
552 | * @param Entry $entry | 549 | * @param Entry $entry |
553 | * | 550 | * @return JsonResponse |
554 | * @ApiDoc( | 551 | * @ApiDoc( |
555 | * requirements={ | 552 | * requirements={ |
556 | * {"name"="ranges", "dataType"="array", "requirement"="\w+", "description"="The range array for the annotation"}, | 553 | * {"name"="ranges", "dataType"="array", "requirement"="\w+", "description"="The range array for the annotation"}, |
@@ -559,34 +556,17 @@ class WallabagRestController extends FOSRestController | |||
559 | * } | 556 | * } |
560 | * ) | 557 | * ) |
561 | * | 558 | * |
562 | * @return Response | ||
563 | */ | 559 | */ |
564 | public function postAnnotationAction(Request $request, Entry $entry) | 560 | public function postAnnotationAction(Request $request, Entry $entry) |
565 | { | 561 | { |
566 | $this->validateAuthentication(); | 562 | $this->validateAuthentication(); |
567 | 563 | ||
568 | $data = json_decode($request->getContent(), true); | 564 | $response = $this->forward('WallabagApiBundle:WallabagRest:postAnnotation', |
569 | 565 | [ | |
570 | $em = $this->getDoctrine()->getManager(); | 566 | 'request' => $request, |
571 | 567 | 'entry' => $entry | |
572 | $annotation = new Annotation($this->getUser()); | 568 | ]); |
573 | 569 | return $response; | |
574 | $annotation->setText($data['text']); | ||
575 | if (array_key_exists('quote', $data)) { | ||
576 | $annotation->setQuote($data['quote']); | ||
577 | } | ||
578 | if (array_key_exists('ranges', $data)) { | ||
579 | $annotation->setRanges($data['ranges']); | ||
580 | } | ||
581 | |||
582 | $annotation->setEntry($entry); | ||
583 | |||
584 | $em->persist($annotation); | ||
585 | $em->flush(); | ||
586 | |||
587 | $json = $this->get('serializer')->serialize($annotation, 'json'); | ||
588 | |||
589 | return $this->renderJsonResponse($json); | ||
590 | } | 570 | } |
591 | 571 | ||
592 | /** | 572 | /** |
@@ -600,24 +580,20 @@ class WallabagRestController extends FOSRestController | |||
600 | * | 580 | * |
601 | * @ParamConverter("annotation", class="WallabagAnnotationBundle:Annotation") | 581 | * @ParamConverter("annotation", class="WallabagAnnotationBundle:Annotation") |
602 | * | 582 | * |
603 | * @return Response | 583 | * @param Annotation $annotation |
584 | * @param Request $request | ||
585 | * @return JsonResponse | ||
604 | */ | 586 | */ |
605 | public function putAnnotationAction(Annotation $annotation, Request $request) | 587 | public function putAnnotationAction(Annotation $annotation, Request $request) |
606 | { | 588 | { |
607 | $this->validateAuthentication(); | 589 | $this->validateAuthentication(); |
608 | 590 | ||
609 | $data = json_decode($request->getContent(), true); | 591 | $response = $this->forward('WallabagApiBundle:WallabagRest:putAnnotation', |
610 | 592 | [ | |
611 | if (!is_null($data['text'])) { | 593 | 'annotation' => $annotation, |
612 | $annotation->setText($data['text']); | 594 | 'request' => $request |
613 | } | 595 | ]); |
614 | 596 | return $response; | |
615 | $em = $this->getDoctrine()->getManager(); | ||
616 | $em->flush(); | ||
617 | |||
618 | $json = $this->get('serializer')->serialize($annotation, 'json'); | ||
619 | |||
620 | return $this->renderJsonResponse($json); | ||
621 | } | 597 | } |
622 | 598 | ||
623 | /** | 599 | /** |
@@ -631,19 +607,18 @@ class WallabagRestController extends FOSRestController | |||
631 | * | 607 | * |
632 | * @ParamConverter("annotation", class="WallabagAnnotationBundle:Annotation") | 608 | * @ParamConverter("annotation", class="WallabagAnnotationBundle:Annotation") |
633 | * | 609 | * |
634 | * @return Response | 610 | * @param Annotation $annotation |
611 | * @return JsonResponse | ||
635 | */ | 612 | */ |
636 | public function deleteAnnotationAction(Annotation $annotation) | 613 | public function deleteAnnotationAction(Annotation $annotation) |
637 | { | 614 | { |
638 | $this->validateAuthentication(); | 615 | $this->validateAuthentication(); |
639 | 616 | ||
640 | $em = $this->getDoctrine()->getManager(); | 617 | $response = $this->forward('WallabagApiBundle:WallabagRest:deleteAnnotation', |
641 | $em->remove($annotation); | 618 | [ |
642 | $em->flush(); | 619 | 'annotation' => $annotation, |
643 | 620 | ]); | |
644 | $json = $this->get('serializer')->serialize($annotation, 'json'); | 621 | return $response; |
645 | |||
646 | return $this->renderJsonResponse($json); | ||
647 | } | 622 | } |
648 | 623 | ||
649 | /** | 624 | /** |