src/Entity/City.php line 32

  1. <?php
  2. namespace App\Entity;
  3. use ApiPlatform\Metadata\Post;
  4. use ApiPlatform\Metadata\Patch;
  5. use Doctrine\ORM\Mapping as ORM;
  6. use App\Repository\CityRepository;
  7. use ApiPlatform\Metadata\ApiFilter;
  8. use ApiPlatform\Metadata\ApiResource;
  9. use ApiPlatform\Metadata\GetCollection;
  10. use ApiPlatform\Doctrine\Orm\Filter\SearchFilter;
  11. use Symfony\Component\Serializer\Annotation\Groups;
  12. #[ORM\Entity(repositoryClassCityRepository::class)]
  13. #[ApiResource(
  14.     operations: [
  15.         new GetCollection(
  16.             normalizationContext: [
  17.                 'groups' => [self::SERIALIZATION_GROUP__FULL_DATA],
  18.             ]
  19.         ),
  20.         new Patch(),
  21.         new Post(),
  22.     ]
  23. )]
  24. #[ApiFilter(SearchFilter::class, properties: [self::NAME_PARAM_NAME => 'exact'])]
  25. /**
  26.  * Contains City model.
  27.  */
  28. class City
  29. {
  30.     public const SERIALIZATION_GROUP__FULL_DATA 'city_full_data';
  31.     public const NAME_PARAM_NAME 'name';
  32.     #[ORM\Id]
  33.     #[ORM\GeneratedValue]
  34.     #[ORM\Column]
  35.     #[Groups([self::SERIALIZATION_GROUP__FULL_DATA])]
  36.     private ?int $id null;
  37.     #[ORM\Column(length255)]
  38.     #[Groups([self::SERIALIZATION_GROUP__FULL_DATA])]
  39.     private ?string $name null;
  40.     #[ORM\Column(length255nullabletrue)]
  41.     #[Groups([self::SERIALIZATION_GROUP__FULL_DATA])]
  42.     private ?string $country null;
  43.     #[ORM\OneToOne(inversedBy'city'targetEntityLivingCostStatistics::class, cascade: ['persist''remove'])]
  44.     #[Groups([self::SERIALIZATION_GROUP__FULL_DATA])]
  45.     private ?LivingCostStatistics $livingCostStatistics null;
  46.     /**
  47.      * Gets Id.
  48.      *
  49.      * @return integer|null
  50.      */
  51.     public function getId(): ?int
  52.     {
  53.         return $this->id;
  54.     }
  55.     /**
  56.      * @return string|null
  57.      */
  58.     public function getName(): ?string
  59.     {
  60.         return $this->name;
  61.     }
  62.     /**
  63.      * @param string $name
  64.      *
  65.      * @return self
  66.      */
  67.     public function setName(string $name): self
  68.     {
  69.         $this->name $name;
  70.         return $this;
  71.     }
  72.     /**
  73.      * @return string|null
  74.      */
  75.     public function getCountry(): ?string
  76.     {
  77.         return $this->country;
  78.     }
  79.     /**
  80.      * @param string|null $country
  81.      *
  82.      * @return self
  83.      */
  84.     public function setCountry(?string $country): self
  85.     {
  86.         $this->country $country;
  87.         return $this;
  88.     }
  89.     /**
  90.      * @return LivingCostStatistics|null
  91.      */
  92.     public function getLivingCostStatistics(): ?LivingCostStatistics
  93.     {
  94.         return $this->livingCostStatistics;
  95.     }
  96.     /**
  97.      * Sets relation to LivingCostStatistics entity.
  98.      *
  99.      * @param LivingCostStatistics|null $livingCostStatistics
  100.      *
  101.      * @return self
  102.      */
  103.     public function setLivingCostStatistics(?LivingCostStatistics $livingCostStatistics): self
  104.     {
  105.         $this->livingCostStatistics $livingCostStatistics;
  106.         return $this;
  107.     }
  108. }