Skip to content
Snippets Groups Projects
Commit 4103687c authored by Reiter, Christoph's avatar Reiter, Christoph :snake:
Browse files

Add a simple data persister

parent 8740c887
No related branches found
No related tags found
No related merge requests found
Pipeline #105579 passed
<?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
}
}
......@@ -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);
}
}
......@@ -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
*/
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment