diff --git a/src/ApiResource/Project/ProjectApiResource.php b/src/ApiResource/Project/ProjectApiResource.php index 6eb3704..4b7e6b6 100644 --- a/src/ApiResource/Project/ProjectApiResource.php +++ b/src/ApiResource/Project/ProjectApiResource.php @@ -9,10 +9,13 @@ use App\ApiResource\Accounting\AccountingApiResource; use App\ApiResource\User\UserApiResource; use App\Entity\Project\Project; use App\Entity\Project\ProjectStatus; +use App\Entity\Project\ProjectVideo; use App\Mapping\Transformer\BudgetMapTransformer; +use App\Mapping\Transformer\ProjectVideoMapTransformer; use App\State\ApiResourceStateProvider; use App\State\Project\ProjectStateProcessor; use AutoMapper\Attribute\MapFrom; +use AutoMapper\Attribute\MapTo; use Symfony\Component\Validator\Constraints as Assert; /** @@ -82,6 +85,21 @@ class ProjectApiResource #[Assert\NotBlank()] public string $description; + /** + * A URL to a video showcasing the Project. + */ + #[Assert\Url()] + #[API\ApiProperty(readable: false)] + #[MapTo(target: Project::class, transformer: ProjectVideoMapTransformer::class)] + public string $video; + + /** + * Extracted embedding data from the Project's video. + */ + #[API\ApiProperty(writable: false)] + #[MapFrom(source: Project::class, property: 'video')] + public ProjectVideo $videoEmbed; + /** * The status of a Project represents how far it is in it's life-cycle. */ diff --git a/src/Entity/Project/Project.php b/src/Entity/Project/Project.php index bd39382..0e949ac 100644 --- a/src/Entity/Project/Project.php +++ b/src/Entity/Project/Project.php @@ -62,6 +62,12 @@ class Project implements UserOwnedInterface, AccountingOwnerInterface, Localized #[ORM\Column(type: Types::TEXT)] private ?string $description = null; + /** + * A video showcasing the Project. + */ + #[ORM\Embedded(class: ProjectVideo::class)] + private ?ProjectVideo $video = null; + /** * Since Projects can be recipients of funding, they are assigned an Accounting when created. * A Project's Accounting represents how much money the Project has raised from the community. @@ -162,6 +168,18 @@ class Project implements UserOwnedInterface, AccountingOwnerInterface, Localized return $this; } + public function getVideo(): ?ProjectVideo + { + return $this->video; + } + + public function setVideo(?ProjectVideo $video): static + { + $this->video = $video; + + return $this; + } + public function getAccounting(): ?Accounting { return $this->accounting; diff --git a/src/Entity/Project/ProjectVideo.php b/src/Entity/Project/ProjectVideo.php new file mode 100644 index 0000000..0ebdc0e --- /dev/null +++ b/src/Entity/Project/ProjectVideo.php @@ -0,0 +1,18 @@ +embedService->getVideo($value); + + return new ProjectVideo($video->src, $video->thumbnail); + } +}