diff --git a/src/ApiPlatform/BookLocation.php b/src/ApiPlatform/BookLocation.php new file mode 100644 index 0000000..b359aca --- /dev/null +++ b/src/ApiPlatform/BookLocation.php @@ -0,0 +1,27 @@ +identifier; + } + + public function setIdentifier(string $identifier): void + { + $this->identifier = $identifier; + } +} diff --git a/src/ApiPlatform/DummyProvider.php b/src/ApiPlatform/DummyProvider.php index d2b8272..cfdfb32 100644 --- a/src/ApiPlatform/DummyProvider.php +++ b/src/ApiPlatform/DummyProvider.php @@ -4,16 +4,21 @@ namespace Dbp\Relay\SublibraryBundle\ApiPlatform; +use ApiPlatform\Metadata\CollectionOperationInterface; use ApiPlatform\Metadata\Operation; use ApiPlatform\State\ProviderInterface; class DummyProvider implements ProviderInterface { /** - * @return null + * @return array|null */ public function provide(Operation $operation, array $uriVariables = [], array $context = []) { - return null; + if (!$operation instanceof CollectionOperationInterface) { + return null; + } + + return []; } } diff --git a/src/Controller/GetLocationIdentifiersByBookOffer.php b/src/ApiPlatform/GetLocationIdentifiersByBookOffer.php similarity index 81% rename from src/Controller/GetLocationIdentifiersByBookOffer.php rename to src/ApiPlatform/GetLocationIdentifiersByBookOffer.php index 5790a02..376709a 100644 --- a/src/Controller/GetLocationIdentifiersByBookOffer.php +++ b/src/ApiPlatform/GetLocationIdentifiersByBookOffer.php @@ -2,8 +2,9 @@ declare(strict_types=1); -namespace Dbp\Relay\SublibraryBundle\Controller; +namespace Dbp\Relay\SublibraryBundle\ApiPlatform; +use Dbp\Relay\SublibraryBundle\Controller\AlmaController; use Dbp\Relay\SublibraryBundle\Helpers\ItemNotLoadedException; use League\Uri\Contracts\UriException; diff --git a/src/Entity/BookLocation.php b/src/Entity/BookLocation.php deleted file mode 100644 index 9a7348c..0000000 --- a/src/Entity/BookLocation.php +++ /dev/null @@ -1,80 +0,0 @@ -identifier; - } - - public function setIdentifier(string $identifier): void - { - $this->identifier = $identifier; - } -} diff --git a/src/Resources/config/api_resources.yaml b/src/Resources/config/api_resources.yaml index 5faeab4..9c3456b 100644 --- a/src/Resources/config/api_resources.yaml +++ b/src/Resources/config/api_resources.yaml @@ -254,7 +254,6 @@ resources: priceCurrency: iri: "http://schema.org/priceCurrency" - Dbp\Relay\SublibraryBundle\ApiPlatform\BookOrder: security: "is_granted('IS_AUTHENTICATED_FULLY') and is_granted('ROLE_LIBRARY_MANAGER')" types: ['http://schema.org/Order'] @@ -302,3 +301,50 @@ resources: iri: "http://schema.org/Text" orderDate: iri: "http://schema.org/DateTime" + + Dbp\Relay\SublibraryBundle\ApiPlatform\BookLocation: + security: "is_granted('IS_AUTHENTICATED_FULLY') and is_granted('ROLE_LIBRARY_MANAGER')" + types: ['https://schema.org/location'] + description: "The location, where a book is shelved." + shortName: "BookLocation" + routePrefix: "/sublibrary" + normalizationContext: + groups: ["BookLocation:output"] + jsonld_embed_context: true + + operations: + + ApiPlatform\Metadata\GetCollection: + security: "is_granted('IS_AUTHENTICATED_FULLY') and is_granted('ROLE_LIBRARY_MANAGER')" + provider: Dbp\Relay\SublibraryBundle\ApiPlatform\DummyProvider + uriTemplate: "/book-locations" + openapiContext: + tags: ["Sublibrary"] + + ApiPlatform\Metadata\Get: + security: "is_granted('IS_AUTHENTICATED_FULLY') and is_granted('ROLE_LIBRARY_MANAGER')" + provider: Dbp\Relay\SublibraryBundle\ApiPlatform\DummyProvider + uriTemplate: "/book-locations/{identifier}" + openapiContext: + tags: ["Sublibrary"] + + get_location_identifiers: + class: ApiPlatform\Metadata\GetCollection + method: GET + controller: Dbp\Relay\SublibraryBundle\ApiPlatform\GetLocationIdentifiersByBookOffer + uriTemplate: "/book-offers/{identifier}/location-identifiers" + read: false + openapiContext: + tags: ["Sublibrary"] + summary: "Retrieves all location identifiers with in the same holding and with the same location as the book offer." + parameters: + - name: identifier + in: path + description: 'Id of book offer' + type: string + required: true + + properties: + identifier: + identifier: true + iri: "http://schema.org/identifier" diff --git a/src/Service/AlmaApi.php b/src/Service/AlmaApi.php index 465925c..bc0b0be 100644 --- a/src/Service/AlmaApi.php +++ b/src/Service/AlmaApi.php @@ -15,6 +15,7 @@ use Dbp\Relay\CoreBundle\Rest\Options; use Dbp\Relay\SublibraryBundle\API\SublibraryProviderInterface; use Dbp\Relay\SublibraryBundle\ApiPlatform\Book; +use Dbp\Relay\SublibraryBundle\ApiPlatform\BookLocation; use Dbp\Relay\SublibraryBundle\ApiPlatform\BookOrder; use Dbp\Relay\SublibraryBundle\ApiPlatform\BookOrderItem; use Dbp\Relay\SublibraryBundle\ApiPlatform\BudgetMonetaryAmount; @@ -22,7 +23,6 @@ use Dbp\Relay\SublibraryBundle\ApiPlatform\EventStatusType; use Dbp\Relay\SublibraryBundle\ApiPlatform\ParcelDelivery; use Dbp\Relay\SublibraryBundle\Entity\BookLoan; -use Dbp\Relay\SublibraryBundle\Entity\BookLocation; use Dbp\Relay\SublibraryBundle\Entity\BookOffer; use Dbp\Relay\SublibraryBundle\Entity\Sublibrary; use Dbp\Relay\SublibraryBundle\Helpers\ItemNotFoundException;