Add territory data to project resources
This commit is contained in:
@@ -66,6 +66,12 @@ class ProjectApiResource
|
||||
#[Assert\NotBlank()]
|
||||
public string $subtitle;
|
||||
|
||||
/**
|
||||
* ISO 3166 data about the Project's territory of interest.
|
||||
*/
|
||||
#[Assert\Valid()]
|
||||
public ProjectTerritory $territory;
|
||||
|
||||
/**
|
||||
* Free-form rich text description for the Project.
|
||||
*/
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace App\ApiResource\Project;
|
||||
|
||||
use Symfony\Component\Validator\Constraints as Assert;
|
||||
|
||||
/**
|
||||
* ISO 3166 data about the Project's territory of interest.
|
||||
*/
|
||||
class ProjectTerritory
|
||||
{
|
||||
/**
|
||||
* ISO 3166-1 alpha-2 two-letter country code.
|
||||
*/
|
||||
#[Assert\NotBlank()]
|
||||
#[Assert\Country(alpha3: false)]
|
||||
public string $country;
|
||||
|
||||
/**
|
||||
* ISO 3166-2 first level subdivision code.\
|
||||
* e.g: ES-AN (Andalucía, Spain)
|
||||
*/
|
||||
public string $subLvl1;
|
||||
|
||||
/**
|
||||
* ISO 3166-2 second level subdivision code.\
|
||||
* e.g: ES-GR (Granada, Andalucía, Spain)
|
||||
*/
|
||||
public string $subLvl2;
|
||||
}
|
||||
@@ -50,6 +50,12 @@ class Project implements UserOwnedInterface, AccountingOwnerInterface, Localized
|
||||
#[Gedmo\Translatable()]
|
||||
private ?string $subtitle = null;
|
||||
|
||||
/**
|
||||
* Project's territory of interest.
|
||||
*/
|
||||
#[ORM\Embedded(class: ProjectTerritory::class)]
|
||||
private ?ProjectTerritory $territory;
|
||||
|
||||
/**
|
||||
* The description body for the Project.
|
||||
*/
|
||||
@@ -125,6 +131,18 @@ class Project implements UserOwnedInterface, AccountingOwnerInterface, Localized
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getTerritory(): ?ProjectTerritory
|
||||
{
|
||||
return $this->territory;
|
||||
}
|
||||
|
||||
public function setTerritory(ProjectTerritory $territory): static
|
||||
{
|
||||
$this->territory = $territory;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getDescription(): ?string
|
||||
{
|
||||
return $this->description;
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
namespace App\Entity\Project;
|
||||
|
||||
use Doctrine\DBAL\Types\Types;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
/**
|
||||
* Represents the territory of interest for a Project.
|
||||
*/
|
||||
#[ORM\Embeddable]
|
||||
class ProjectTerritory
|
||||
{
|
||||
#[ORM\Column(type: Types::STRING, nullable: false)]
|
||||
public readonly string $country;
|
||||
|
||||
/**
|
||||
* First-level sub-division of the country.
|
||||
*/
|
||||
#[ORM\Column(type: Types::STRING, nullable: true)]
|
||||
public readonly ?string $subLvl1;
|
||||
|
||||
/**
|
||||
* Second-level sub-division of the country.
|
||||
*/
|
||||
#[ORM\Column(type: Types::STRING, nullable: true)]
|
||||
public readonly ?string $subLvl2;
|
||||
|
||||
public function __construct(
|
||||
string $country,
|
||||
?string $subLvl1 = null,
|
||||
?string $subLvl2 = null
|
||||
)
|
||||
{
|
||||
$this->country = $country;
|
||||
$this->subLvl1 = $subLvl1 ?? null;
|
||||
$this->subLvl2 = $subLvl2 ?? null;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user