wallabag/src/Wallabag/CoreBundle/Controller/Api/AnnotationRestController.php

188 lines
5.6 KiB
PHP
Raw Normal View History

2016-11-03 16:29:16 +00:00
<?php
2023-12-31 08:28:37 +00:00
namespace Wallabag\CoreBundle\Controller\Api;
2016-11-03 16:29:16 +00:00
use Nelmio\ApiDocBundle\Annotation\Operation;
use OpenApi\Annotations as OA;
2017-07-01 07:52:38 +00:00
use Symfony\Component\HttpFoundation\Request;
2023-08-08 01:27:21 +00:00
use Symfony\Component\HttpFoundation\Response;
2022-11-23 11:44:55 +00:00
use Symfony\Component\Routing\Annotation\Route;
2023-12-25 17:50:29 +00:00
use Wallabag\CoreBundle\Entity\Annotation;
2017-07-01 07:52:38 +00:00
use Wallabag\CoreBundle\Entity\Entry;
2016-11-03 16:29:16 +00:00
class AnnotationRestController extends WallabagRestController
{
/**
* Retrieve annotations for an entry.
*
* @Operation(
* tags={"Annotations"},
* summary="Retrieve annotations for an entry.",
* @OA\Parameter(
* name="entry",
* in="path",
* description="The entry ID",
* required=true,
* @OA\Schema(
* type="integer",
* pattern="\w+",
* )
* ),
* @OA\Response(
* response="200",
* description="Returned when successful"
* )
2016-11-03 16:29:16 +00:00
* )
*
2022-11-23 11:44:55 +00:00
* @Route("/api/annotations/{entry}.{_format}", methods={"GET"}, name="api_get_annotations", defaults={"_format": "json"})
*
2023-08-08 01:27:21 +00:00
* @return Response
2016-11-03 16:29:16 +00:00
*/
public function getAnnotationsAction(Entry $entry)
{
$this->validateAuthentication();
2023-12-25 17:37:15 +00:00
return $this->forward('Wallabag\CoreBundle\Controller\AnnotationController::getAnnotationsAction', [
2016-11-03 16:29:16 +00:00
'entry' => $entry,
]);
}
/**
* Creates a new annotation.
*
* @Operation(
* tags={"Annotations"},
* summary="Creates a new annotation.",
* @OA\Parameter(
* name="entry",
* in="path",
* description="The entry ID",
* required=true,
* @OA\Schema(
* type="integer",
* pattern="\w+",
* )
* ),
* @OA\RequestBody(
* @OA\JsonContent(
* type="object",
* required={"text"},
* @OA\Property(
* property="ranges",
* type="array",
* description="The range array for the annotation",
* @OA\Items(
* type="string",
* pattern="\w+",
* )
* ),
* @OA\Property(
* property="quote",
* type="array",
* description="The annotated text",
* @OA\Items(
* type="string",
* )
* ),
* @OA\Property(
* property="text",
* type="array",
* description="Content of annotation",
* @OA\Items(
* type="string",
* )
* ),
* )
* ),
* @OA\Response(
* response="200",
* description="Returned when successful"
* )
2016-11-03 16:29:16 +00:00
* )
*
2022-11-23 11:44:55 +00:00
* @Route("/api/annotations/{entry}.{_format}", methods={"POST"}, name="api_post_annotation", defaults={"_format": "json"})
*
2023-08-08 01:27:21 +00:00
* @return Response
2016-11-03 16:29:16 +00:00
*/
public function postAnnotationAction(Request $request, Entry $entry)
{
$this->validateAuthentication();
2023-12-25 17:37:15 +00:00
return $this->forward('Wallabag\CoreBundle\Controller\AnnotationController::postAnnotationAction', [
2016-11-03 16:29:16 +00:00
'request' => $request,
'entry' => $entry,
]);
}
/**
* Updates an annotation.
*
* @Operation(
* tags={"Annotations"},
* summary="Updates an annotation.",
* @OA\Parameter(
* name="annotation",
* in="path",
* description="The annotation ID",
* required=true,
* @OA\Schema(
* type="string",
* pattern="\w+",
* )
* ),
* @OA\Response(
* response="200",
* description="Returned when successful"
* )
2016-11-03 16:29:16 +00:00
* )
*
2022-11-23 11:44:55 +00:00
* @Route("/api/annotations/{annotation}.{_format}", methods={"PUT"}, name="api_put_annotation", defaults={"_format": "json"})
2016-11-03 16:29:16 +00:00
*
2023-08-08 01:27:21 +00:00
* @return Response
2016-11-03 16:29:16 +00:00
*/
public function putAnnotationAction(int $annotation, Request $request)
2016-11-03 16:29:16 +00:00
{
$this->validateAuthentication();
2023-12-25 17:37:15 +00:00
return $this->forward('Wallabag\CoreBundle\Controller\AnnotationController::putAnnotationAction', [
2016-11-03 16:29:16 +00:00
'annotation' => $annotation,
'request' => $request,
]);
}
/**
* Removes an annotation.
*
* @Operation(
* tags={"Annotations"},
* summary="Removes an annotation.",
* @OA\Parameter(
* name="annotation",
* in="path",
* description="The annotation ID",
* required=true,
* @OA\Schema(
* type="string",
* pattern="\w+",
* )
* ),
* @OA\Response(
* response="200",
* description="Returned when successful"
* )
2016-11-03 16:29:16 +00:00
* )
*
2022-11-23 11:44:55 +00:00
* @Route("/api/annotations/{annotation}.{_format}", methods={"DELETE"}, name="api_delete_annotation", defaults={"_format": "json"})
2016-11-03 16:29:16 +00:00
*
2023-08-08 01:27:21 +00:00
* @return Response
2016-11-03 16:29:16 +00:00
*/
public function deleteAnnotationAction(int $annotation)
2016-11-03 16:29:16 +00:00
{
$this->validateAuthentication();
2023-12-25 17:37:15 +00:00
return $this->forward('Wallabag\CoreBundle\Controller\AnnotationController::deleteAnnotationAction', [
2016-11-03 16:29:16 +00:00
'annotation' => $annotation,
]);
}
}