From 6e01b5f73dd1fad2dbff194f843b1f4f26f4bbc3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Ig=C3=B3n?= Date: Mon, 15 Apr 2024 13:16:32 +0200 Subject: [PATCH 1/5] add new fields for project and create ProjectStatus enum --- src/Entity/Project.php | 56 +++++++++++++++++++++++++++++++++++- src/Entity/ProjectStatus.php | 14 +++++++++ 2 files changed, 69 insertions(+), 1 deletion(-) create mode 100644 src/Entity/ProjectStatus.php diff --git a/src/Entity/Project.php b/src/Entity/Project.php index 76fd22a..0c9d21e 100644 --- a/src/Entity/Project.php +++ b/src/Entity/Project.php @@ -5,7 +5,9 @@ namespace App\Entity; use ApiPlatform\Doctrine\Orm\Filter\SearchFilter; use ApiPlatform\Metadata as API; use App\Repository\ProjectRepository; +use App\Entity\ProjectStatus as Status; use Doctrine\ORM\Mapping as ORM; +use Doctrine\ORM\Mapping\Entity; /** * Projects describe a community-led event that is to be discovered, developed and funded by other Users.\ @@ -19,7 +21,10 @@ use Doctrine\ORM\Mapping as ORM; #[API\Put(security: 'is_granted("AUTH_PROJECT_EDIT")')] #[API\Delete(security: 'is_granted("AUTH_PROJECT_EDIT")')] #[API\Patch(security: 'is_granted("AUTH_PROJECT_EDIT")')] -#[API\ApiFilter(filterClass: SearchFilter::class, properties: ['title' => 'partial'])] +#[API\ApiFilter(filterClass: SearchFilter::class, properties: [ + 'title' => 'partial', + 'status', 'owner' +])] #[ORM\Entity(repositoryClass: ProjectRepository::class)] class Project { @@ -36,6 +41,19 @@ class Project #[ORM\JoinColumn(nullable: false)] private ?Accounting $accounting = null; + #[API\ApiProperty(writable: false)] + #[ORM\OneToOne(cascade: ['persist', 'remove'])] + #[ORM\JoinColumn(nullable: false)] + private User $owner; + + #[API\ApiProperty(writable: true)] + #[ORM\Column(type: 'int', enumType: Status::class)] + private Status $status; + + #[Orm\Column()] + #[API\ApiProperty(writable: false)] + private int $amount; + public function __construct() { $this->accounting = new Accounting(); @@ -70,4 +88,40 @@ class Project return $this; } + + public function setOwner(User $owner): static + { + $this->owner = $owner; + + return $this; + } + + public function getOwner(): User + { + return $this->owner; + } + + public function setStatus(string $status): static + { + $this->status = $status; + + return $this; + } + + public function getStatus(): string + { + return $this->status; + } + + public function setAmount(int $amount): static + { + $this->amount = $amount; + + return $this; + } + + public function getAmount(): int + { + return $this->amount; + } } diff --git a/src/Entity/ProjectStatus.php b/src/Entity/ProjectStatus.php new file mode 100644 index 0000000..20e2a71 --- /dev/null +++ b/src/Entity/ProjectStatus.php @@ -0,0 +1,14 @@ + Date: Mon, 15 Apr 2024 14:21:15 +0200 Subject: [PATCH 2/5] add timestampable to project --- src/Entity/Project.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Entity/Project.php b/src/Entity/Project.php index 0c9d21e..b64f3f1 100644 --- a/src/Entity/Project.php +++ b/src/Entity/Project.php @@ -7,7 +7,7 @@ use ApiPlatform\Metadata as API; use App\Repository\ProjectRepository; use App\Entity\ProjectStatus as Status; use Doctrine\ORM\Mapping as ORM; -use Doctrine\ORM\Mapping\Entity; +use Gedmo\Timestampable\Traits\TimestampableEntity; /** * Projects describe a community-led event that is to be discovered, developed and funded by other Users.\ @@ -54,6 +54,8 @@ class Project #[API\ApiProperty(writable: false)] private int $amount; + use TimestampableEntity; + public function __construct() { $this->accounting = new Accounting(); @@ -108,7 +110,7 @@ class Project return $this; } - public function getStatus(): string + public function getStatus(): Status { return $this->status; } From d99033fcf8baf533c5884a5cffb9886aaa6330ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Ig=C3=B3n?= Date: Mon, 15 Apr 2024 18:16:19 +0200 Subject: [PATCH 3/5] change amount type from int to Money --- src/Entity/Project.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Entity/Project.php b/src/Entity/Project.php index b64f3f1..24c4dcf 100644 --- a/src/Entity/Project.php +++ b/src/Entity/Project.php @@ -50,9 +50,9 @@ class Project #[ORM\Column(type: 'int', enumType: Status::class)] private Status $status; - #[Orm\Column()] #[API\ApiProperty(writable: false)] - private int $amount; + #[ORM\Column(type: 'int')] + private ?Money $amount; use TimestampableEntity; From 8c54b100da4caf15eb889e6a6ad6583689463a51 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Ig=C3=B3n?= Date: Mon, 15 Apr 2024 18:16:51 +0200 Subject: [PATCH 4/5] refactor project status enum --- src/Entity/Project.php | 2 +- src/Entity/ProjectStatus.php | 16 ++++++++-------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/Entity/Project.php b/src/Entity/Project.php index 24c4dcf..257c2e5 100644 --- a/src/Entity/Project.php +++ b/src/Entity/Project.php @@ -47,7 +47,7 @@ class Project private User $owner; #[API\ApiProperty(writable: true)] - #[ORM\Column(type: 'int', enumType: Status::class)] + #[ORM\Column(type: 'string', enumType: Status::class)] private Status $status; #[API\ApiProperty(writable: false)] diff --git a/src/Entity/ProjectStatus.php b/src/Entity/ProjectStatus.php index 20e2a71..04c5b81 100644 --- a/src/Entity/ProjectStatus.php +++ b/src/Entity/ProjectStatus.php @@ -2,13 +2,13 @@ namespace App\Entity; -enum ProjectStatus: int +enum ProjectStatus: string { - case REJECTED = 0; - case EDITING = 1; - case REVIEWING = 2; - case IN_CAMPAIGN = 3; - case FUNDED = 4; - case FULFILLED = 5; - case UNFUNDED = 6; + case Rejected = 'rejected'; + case Editing = 'editing'; + case Reviewing = 'reviewing'; + case InCampaign = 'in_campaign'; + case Funded = 'funded'; + case Fulfilled = 'fulfilled'; + case Unfunded = 'unfunded'; } From 499aec84d4535089df216e2307a9ed0fa1b7a566 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Ig=C3=B3n?= Date: Thu, 25 Apr 2024 17:03:55 +0200 Subject: [PATCH 5/5] remove amount field --- src/Entity/Project.php | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/src/Entity/Project.php b/src/Entity/Project.php index 257c2e5..6cdc18a 100644 --- a/src/Entity/Project.php +++ b/src/Entity/Project.php @@ -50,10 +50,6 @@ class Project #[ORM\Column(type: 'string', enumType: Status::class)] private Status $status; - #[API\ApiProperty(writable: false)] - #[ORM\Column(type: 'int')] - private ?Money $amount; - use TimestampableEntity; public function __construct() @@ -114,16 +110,4 @@ class Project { return $this->status; } - - public function setAmount(int $amount): static - { - $this->amount = $amount; - - return $this; - } - - public function getAmount(): int - { - return $this->amount; - } }