From 21b3a72c30f1b28cfe51210fb72def04be3b785b Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Nicol=C3=B2=20P?= <nicolo.paraciani@cnr.it>
Date: Fri, 13 Dec 2024 09:24:12 +0100
Subject: [PATCH] Add entities (WIP)

---
 config/packages/api_platform.yaml        |  1 +
 src/Entity/Degradation.php               | 91 ++++++++++++++++++++++++
 src/Entity/Material.php                  | 42 +++++++++++
 src/Repository/DegradationRepository.php | 43 +++++++++++
 src/Repository/MaterialRepository.php    | 43 +++++++++++
 5 files changed, 220 insertions(+)
 create mode 100644 src/Entity/Degradation.php
 create mode 100644 src/Entity/Material.php
 create mode 100644 src/Repository/DegradationRepository.php
 create mode 100644 src/Repository/MaterialRepository.php

diff --git a/config/packages/api_platform.yaml b/config/packages/api_platform.yaml
index 3cab672..edabbae 100644
--- a/config/packages/api_platform.yaml
+++ b/config/packages/api_platform.yaml
@@ -1,6 +1,7 @@
 api_platform:
     title: Architetture Roma - API
     version: beta
+    show_webby: false
     defaults:
         stateless: true
         cache_headers:
diff --git a/src/Entity/Degradation.php b/src/Entity/Degradation.php
new file mode 100644
index 0000000..bf4eb0a
--- /dev/null
+++ b/src/Entity/Degradation.php
@@ -0,0 +1,91 @@
+<?php
+
+namespace App\Entity;
+
+use ApiPlatform\Metadata\ApiResource;
+use ApiPlatform\Metadata\Get;
+use ApiPlatform\Metadata\GetCollection;
+use App\Repository\DegradationRepository;
+use Doctrine\DBAL\Types\Types;
+use Doctrine\ORM\Mapping as ORM;
+use Symfony\Component\Serializer\Attribute\Groups;
+
+#[ORM\Entity(repositoryClass: DegradationRepository::class)]
+#[ORM\Table(name: 'degrado')]
+#[ApiResource(
+    operations: [
+        new Get(normalizationContext: ['groups' => 'degradation:item']),
+        new GetCollection(normalizationContext: ['groups' => 'degradation:list'])
+    ],
+    order: ['term' => 'DESC'],
+    paginationEnabled: false,
+)]
+class Degradation
+{
+    #[ORM\Id]
+    #[ORM\GeneratedValue]
+    #[ORM\Column]
+    #[Groups(['degradation:list', 'degradation:item'])]
+    private ?int $id = null;
+
+    #[ORM\Column(length: 50, name: 'lemma')]
+    #[Groups(['degradation:list', 'degradation:item'])]
+    private ?string $term = null;
+
+    #[ORM\Column(length: 50, nullable: true, name: 'classe')]
+    #[Groups(['degradation:list', 'degradation:item'])]
+    private ?string $class = null;
+
+    #[ORM\Column(type: Types::BIGINT, nullable: true, name: 'materiale')]
+    //#[ORM\ManyToOne()]
+    #[Groups(['degradation:list', 'degradation:item'])]
+    private ?string $material = null;
+
+    public function getId(): ?int
+    {
+        return $this->id;
+    }
+
+    public function setId(string $id): static
+    {
+        $this->id = $id;
+
+        return $this;
+    }
+
+    public function getTerm(): ?string
+    {
+        return $this->term;
+    }
+
+    public function setTerm(string $term): static
+    {
+        $this->term = $term;
+
+        return $this;
+    }
+
+    public function getClass(): ?string
+    {
+        return $this->class;
+    }
+
+    public function setClass(?string $class): static
+    {
+        $this->class = $class;
+
+        return $this;
+    }
+
+    public function getMaterial(): ?string
+    {
+        return $this->material;
+    }
+
+    public function setMaterial(?string $material): static
+    {
+        $this->material = $material;
+
+        return $this;
+    }
+}
diff --git a/src/Entity/Material.php b/src/Entity/Material.php
new file mode 100644
index 0000000..74e0f3a
--- /dev/null
+++ b/src/Entity/Material.php
@@ -0,0 +1,42 @@
+<?php
+
+namespace App\Entity;
+
+use App\Repository\MaterialRepository;
+use Doctrine\ORM\Mapping as ORM;
+
+#[ORM\Entity(repositoryClass: MaterialRepository::class)]
+class Material
+{
+    #[ORM\Id]
+    #[ORM\GeneratedValue]
+    #[ORM\Column]
+    private ?int $id = null;
+
+    #[ORM\Column(length: 50)]
+    private ?string $term = null;
+
+    public function getId(): ?int
+    {
+        return $this->id;
+    }
+
+    public function setId(string $id): static
+    {
+        $this->id = $id;
+
+        return $this;
+    }
+
+    public function getTerm(): ?string
+    {
+        return $this->term;
+    }
+
+    public function setTerm(string $term): static
+    {
+        $this->term = $term;
+
+        return $this;
+    }
+}
diff --git a/src/Repository/DegradationRepository.php b/src/Repository/DegradationRepository.php
new file mode 100644
index 0000000..833f0a1
--- /dev/null
+++ b/src/Repository/DegradationRepository.php
@@ -0,0 +1,43 @@
+<?php
+
+namespace App\Repository;
+
+use App\Entity\Degradation;
+use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
+use Doctrine\Persistence\ManagerRegistry;
+
+/**
+ * @extends ServiceEntityRepository<Degradation>
+ */
+class DegradationRepository extends ServiceEntityRepository
+{
+    public function __construct(ManagerRegistry $registry)
+    {
+        parent::__construct($registry, Degradation::class);
+    }
+
+    //    /**
+    //     * @return Degradation[] Returns an array of Degradation objects
+    //     */
+    //    public function findByExampleField($value): array
+    //    {
+    //        return $this->createQueryBuilder('d')
+    //            ->andWhere('d.exampleField = :val')
+    //            ->setParameter('val', $value)
+    //            ->orderBy('d.id', 'ASC')
+    //            ->setMaxResults(10)
+    //            ->getQuery()
+    //            ->getResult()
+    //        ;
+    //    }
+
+    //    public function findOneBySomeField($value): ?Degradation
+    //    {
+    //        return $this->createQueryBuilder('d')
+    //            ->andWhere('d.exampleField = :val')
+    //            ->setParameter('val', $value)
+    //            ->getQuery()
+    //            ->getOneOrNullResult()
+    //        ;
+    //    }
+}
diff --git a/src/Repository/MaterialRepository.php b/src/Repository/MaterialRepository.php
new file mode 100644
index 0000000..0d4a7ff
--- /dev/null
+++ b/src/Repository/MaterialRepository.php
@@ -0,0 +1,43 @@
+<?php
+
+namespace App\Repository;
+
+use App\Entity\Material;
+use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
+use Doctrine\Persistence\ManagerRegistry;
+
+/**
+ * @extends ServiceEntityRepository<Material>
+ */
+class MaterialRepository extends ServiceEntityRepository
+{
+    public function __construct(ManagerRegistry $registry)
+    {
+        parent::__construct($registry, Material::class);
+    }
+
+    //    /**
+    //     * @return Material[] Returns an array of Material objects
+    //     */
+    //    public function findByExampleField($value): array
+    //    {
+    //        return $this->createQueryBuilder('m')
+    //            ->andWhere('m.exampleField = :val')
+    //            ->setParameter('val', $value)
+    //            ->orderBy('m.id', 'ASC')
+    //            ->setMaxResults(10)
+    //            ->getQuery()
+    //            ->getResult()
+    //        ;
+    //    }
+
+    //    public function findOneBySomeField($value): ?Material
+    //    {
+    //        return $this->createQueryBuilder('m')
+    //            ->andWhere('m.exampleField = :val')
+    //            ->setParameter('val', $value)
+    //            ->getQuery()
+    //            ->getOneOrNullResult()
+    //        ;
+    //    }
+}