diff --git a/src/DataPersister/PlaceDataPersister.php b/src/DataPersister/PlaceDataPersister.php new file mode 100644 index 0000000000000000000000000000000000000000..c9b8631548c824b549f2e1afa62d2f0527ee9e44 --- /dev/null +++ b/src/DataPersister/PlaceDataPersister.php @@ -0,0 +1,34 @@ +<?php + +declare(strict_types=1); + +namespace DBP\API\StarterBundle\DataPersister; + +use ApiPlatform\Core\DataPersister\DataPersisterInterface; +use DBP\API\StarterBundle\Entity\Place; +use DBP\API\StarterBundle\Service\PlaceProviderInterface; + +class PlaceDataPersister implements DataPersisterInterface +{ + private $api; + + public function __construct(PlaceProviderInterface $api) + { + $this->api = $api; + } + + public function supports($data): bool + { + return $data instanceof Place; + } + + public function persist($data) + { + // TODO + } + + public function remove($data) + { + // TODO + } +} diff --git a/src/DataProvider/PlaceItemDataProvider.php b/src/DataProvider/PlaceItemDataProvider.php index e69721fb6ba423842929780293124b3922e4fc0d..51029e0a53eb88560d52a0c5b844931b26058d2d 100644 --- a/src/DataProvider/PlaceItemDataProvider.php +++ b/src/DataProvider/PlaceItemDataProvider.php @@ -8,7 +8,6 @@ use ApiPlatform\Core\DataProvider\ItemDataProviderInterface; use ApiPlatform\Core\DataProvider\RestrictedDataProviderInterface; use DBP\API\StarterBundle\Entity\Place; use DBP\API\StarterBundle\Service\PlaceProviderInterface; -use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; final class PlaceItemDataProvider implements ItemDataProviderInterface, RestrictedDataProviderInterface { @@ -27,13 +26,8 @@ final class PlaceItemDataProvider implements ItemDataProviderInterface, Restrict /** * @param array|int|string $id */ - public function getItem(string $resourceClass, $id, string $operationName = null, array $context = []): Place + public function getItem(string $resourceClass, $id, string $operationName = null, array $context = []): ?Place { - $place = $this->api->getPlaceById($id); - if ($place === null) { - throw new NotFoundHttpException(); - } - - return $place; + return $this->api->getPlaceById($id); } } diff --git a/src/Entity/Place.php b/src/Entity/Place.php index ef50736d3ad14c701d451192633a3b3ca398abbe..95506c5afcf4c7920b07b27344091c78b77c3552 100644 --- a/src/Entity/Place.php +++ b/src/Entity/Place.php @@ -11,9 +11,10 @@ use Symfony\Component\Serializer\Annotation\Groups; /** * @ApiResource( * collectionOperations={"get"}, - * itemOperations={"get"}, + * itemOperations={"get", "put", "delete"}, * iri="https://schema.org/Place", - * normalizationContext={"groups"={"Place:output"}, "jsonld_embed_context"=true} + * normalizationContext={"groups"={"Place:output"}, "jsonld_embed_context"=true}, + * denormalizationContext={"groups"={"Place:input"}, "jsonld_embed_context"=true} * ) */ class Place @@ -25,7 +26,7 @@ class Place /** * @ApiProperty(iri="https://schema.org/name") - * @Groups({"Place:output"}) + * @Groups({"Place:output", "Place:input"}) * * @var string */