From 32ad965139d132377ba9cad39ef77d0d9f0a4230 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=B2=20P=2E?= Date: Sat, 14 Dec 2024 18:00:49 +0100 Subject: [PATCH] Add Element entity + API for Material --- src/Entity/Element.php | 184 +++++++++++++++++++++++++++ src/Entity/Material.php | 17 ++- src/Repository/ElementRepository.php | 43 +++++++ 3 files changed, 243 insertions(+), 1 deletion(-) create mode 100644 src/Entity/Element.php create mode 100644 src/Repository/ElementRepository.php diff --git a/src/Entity/Element.php b/src/Entity/Element.php new file mode 100644 index 0000000..2dc10d7 --- /dev/null +++ b/src/Entity/Element.php @@ -0,0 +1,184 @@ + 'element:item']), + new GetCollection(normalizationContext: ['groups' => 'element:list']) + ], + order: ['label' => 'DESC'], + paginationEnabled: false, +)] +class Element +{ + #[ORM\Id] + #[ORM\GeneratedValue] + #[ORM\Column] + #[Groups(['element:list', 'element:item'])] + private ?int $id = null; + + #[ORM\Column(name: 'etichetta', length: 6)] + #[Groups(['element:list', 'element:item'])] + private ?string $label = null; + + #[ORM\Column(name: 'rango', length: 50, nullable: true)] + #[Groups(['element:list', 'element:item'])] + private ?string $rank = null; + + #[ORM\Column(name: 'tipo', type: Types::BIGINT, nullable: true)] + #[Groups(['element:list', 'element:item'])] + private ?string $type = null; + + #[ORM\Column(name: 'materiale', type: Types::BIGINT, nullable: true)] + #[ORM\ManyToOne(targetEntity: Material::class)] + #[JoinColumn(name: 'materiale', referencedColumnName: 'id')] + #[Groups(['element:list', 'element:item'])] + private ?string $material = null; + + #[ORM\Column(name: 'lavorazione', type: Types::BIGINT, nullable: true)] + private ?string $production = null; + + #[ORM\Column(name: 'posa', type: Types::BIGINT, nullable: true)] + private ?string $placement = null; + + #[ORM\Column(name: 'strutt_oriz', type: Types::BIGINT)] + private ?string $horizontalStructure = null; + + #[ORM\Column(name: 'riconoscimento', type: Types::BIGINT, nullable: true)] + private ?string $identification = null; + + #[ORM\Column(name: 'note', type: Types::TEXT, nullable: true)] + #[Groups(['element:list', 'element:item'])] + private ?string $notes = null; + + public function getId(): ?int + { + return $this->id; + } + + public function setId(string $id): static + { + $this->id = $id; + + return $this; + } + + public function getLabel(): ?string + { + return $this->label; + } + + public function setLabel(string $label): static + { + $this->label = $label; + + return $this; + } + + public function getRank(): ?string + { + return $this->rank; + } + + public function setRank(?string $rank): static + { + $this->rank = $rank; + + return $this; + } + + public function getType(): ?string + { + return $this->type; + } + + public function setType(?string $type): static + { + $this->type = $type; + + return $this; + } + + public function getMaterial(): ?string + { + return $this->material; + } + + public function setMaterial(?string $material): static + { + $this->material = $material; + + return $this; + } + + public function getProduction(): ?string + { + return $this->production; + } + + public function setProduction(?string $production): static + { + $this->production = $production; + + return $this; + } + + public function getPlacement(): ?string + { + return $this->placement; + } + + public function setPlacement(?string $placement): static + { + $this->placement = $placement; + + return $this; + } + + public function getHorizontalStructure(): ?string + { + return $this->horizontalStructure; + } + + public function setHorizontalStructure(string $horizontalStructure): static + { + $this->horizontalStructure = $horizontalStructure; + + return $this; + } + + public function getIdentification(): ?string + { + return $this->identification; + } + + public function setIdentification(?string $identification): static + { + $this->identification = $identification; + + return $this; + } + + public function getNotes(): ?string + { + return $this->notes; + } + + public function setNotes(?string $notes): static + { + $this->notes = $notes; + + return $this; + } +} diff --git a/src/Entity/Material.php b/src/Entity/Material.php index 74e0f3a..7c59292 100644 --- a/src/Entity/Material.php +++ b/src/Entity/Material.php @@ -2,18 +2,33 @@ namespace App\Entity; +use ApiPlatform\Metadata\ApiResource; +use ApiPlatform\Metadata\Get; +use ApiPlatform\Metadata\GetCollection; use App\Repository\MaterialRepository; use Doctrine\ORM\Mapping as ORM; +use Symfony\Component\Serializer\Attribute\Groups; #[ORM\Entity(repositoryClass: MaterialRepository::class)] +#[ORM\Table(name: 'voc_materiale')] +#[ApiResource( + operations: [ + new Get(normalizationContext: ['groups' => 'material:item']), + new GetCollection(normalizationContext: ['groups' => 'material:list']) + ], + order: ['term' => 'DESC'], + paginationEnabled: false, +)] class Material { #[ORM\Id] #[ORM\GeneratedValue] #[ORM\Column] + #[Groups(['material:list', 'material:item'])] private ?int $id = null; - #[ORM\Column(length: 50)] + #[ORM\Column(name: 'lemma', length: 50)] + #[Groups(['material:list', 'material:item'])] private ?string $term = null; public function getId(): ?int diff --git a/src/Repository/ElementRepository.php b/src/Repository/ElementRepository.php new file mode 100644 index 0000000..13bbe9d --- /dev/null +++ b/src/Repository/ElementRepository.php @@ -0,0 +1,43 @@ + + */ +class ElementRepository extends ServiceEntityRepository +{ + public function __construct(ManagerRegistry $registry) + { + parent::__construct($registry, Element::class); + } + + // /** + // * @return Element[] Returns an array of Element objects + // */ + // public function findByExampleField($value): array + // { + // return $this->createQueryBuilder('e') + // ->andWhere('e.exampleField = :val') + // ->setParameter('val', $value) + // ->orderBy('e.id', 'ASC') + // ->setMaxResults(10) + // ->getQuery() + // ->getResult() + // ; + // } + + // public function findOneBySomeField($value): ?Element + // { + // return $this->createQueryBuilder('e') + // ->andWhere('e.exampleField = :val') + // ->setParameter('val', $value) + // ->getQuery() + // ->getOneOrNullResult() + // ; + // } +}