From 09ebe7ddeddf9e03f19cd5c1f3f8276490d04be7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=B2=20P?= Date: Mon, 16 Dec 2024 17:56:51 +0100 Subject: [PATCH] Allow JSON media type + POST for Building (WIP) --- config/packages/api_platform.yaml | 5 +++++ src/Entity/Building.php | 5 ++++- src/Entity/Element.php | 4 +++- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/config/packages/api_platform.yaml b/config/packages/api_platform.yaml index edabbae..f3443a2 100644 --- a/config/packages/api_platform.yaml +++ b/config/packages/api_platform.yaml @@ -2,6 +2,11 @@ api_platform: title: Architetture Roma - API version: beta show_webby: false + formats: + json: + mime_types: ['application/json'] + jsonld: + mime_types: ['application/ld+json'] defaults: stateless: true cache_headers: diff --git a/src/Entity/Building.php b/src/Entity/Building.php index 09ed468..0d7cb22 100644 --- a/src/Entity/Building.php +++ b/src/Entity/Building.php @@ -4,6 +4,7 @@ namespace App\Entity; use ApiPlatform\Metadata\ApiResource; use ApiPlatform\Metadata\Get; +use ApiPlatform\Metadata\Post; use ApiPlatform\Metadata\GetCollection; use App\Repository\BuildingRepository; use Doctrine\ORM\Mapping as ORM; @@ -14,7 +15,9 @@ use Symfony\Component\Serializer\Attribute\Groups; #[ApiResource( operations: [ new Get(normalizationContext: ['groups' => 'building:item']), - new GetCollection(normalizationContext: ['groups' => 'building:list']) + new GetCollection(normalizationContext: ['groups' => 'building:list']), + // TODO Security!! + new Post(), ], order: ['name' => 'DESC'], paginationEnabled: false, diff --git a/src/Entity/Element.php b/src/Entity/Element.php index 2dc10d7..aa9f352 100644 --- a/src/Entity/Element.php +++ b/src/Entity/Element.php @@ -3,6 +3,7 @@ namespace App\Entity; use ApiPlatform\Metadata\ApiResource; +use ApiPlatform\Metadata\ApiProperty; use ApiPlatform\Metadata\Get; use ApiPlatform\Metadata\GetCollection; use App\Repository\ElementRepository; @@ -42,8 +43,9 @@ class Element #[ORM\Column(name: 'materiale', type: Types::BIGINT, nullable: true)] #[ORM\ManyToOne(targetEntity: Material::class)] - #[JoinColumn(name: 'materiale', referencedColumnName: 'id')] + #[ORM\JoinColumn(name: 'materiale', referencedColumnName: 'id')] #[Groups(['element:list', 'element:item'])] + #[ApiProperty(uriTemplate: '/materials/{id}')] private ?string $material = null; #[ORM\Column(name: 'lavorazione', type: Types::BIGINT, nullable: true)]