-
Notifications
You must be signed in to change notification settings - Fork 62
Feature/embedded entities #1682
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 5 commits
ad23675
97f7408
7d76aa2
761acd0
e5d69f7
a2f3007
90f03ee
23c83ee
7205e60
3ff4f41
e7c3516
c94ed0d
5847e8c
8153a0a
f6d07a2
25bd154
eea56b9
c98a70a
5b029cd
4895495
4e08a3e
c65be86
b0cb899
e69b947
1e74ed3
476731b
a62928f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,6 +11,7 @@ | |
| use Doctrine\Common\Collections\Collection; | ||
| use Doctrine\ORM\Mapping as ORM; | ||
| use Symfony\Component\Serializer\Annotation\Groups; | ||
| use Symfony\Component\Serializer\Annotation\SerializedName; | ||
| use Symfony\Component\Validator\Constraints as Assert; | ||
|
|
||
| /** | ||
|
|
@@ -20,15 +21,28 @@ | |
| * @ORM\Entity | ||
| */ | ||
| #[ApiResource( | ||
| collectionOperations: ['get', 'post'], | ||
| itemOperations: [ | ||
| collectionOperations: [ | ||
| 'get', | ||
| 'patch' => ['denormalization_context' => [ | ||
| 'groups' => ['period:update'], | ||
| 'allow_extra_attributes' => false, | ||
| ]], | ||
| 'post', | ||
| ], | ||
| itemOperations: [ | ||
| 'get' => [ | ||
| 'normalization_context' => [ | ||
| 'groups' => ['read', 'Period:Camp', 'Period:Days'], | ||
| 'allow_extra_attributes' => false, | ||
| ], | ||
| ], | ||
| 'patch', | ||
| 'delete', | ||
| ] | ||
| ], | ||
| normalizationContext: [ | ||
| 'groups' => ['read'], | ||
| 'allow_extra_attributes' => false, | ||
| ], | ||
| denormalizationContext: [ | ||
| 'groups' => ['write'], | ||
| 'allow_extra_attributes' => false, | ||
| ], | ||
| )] | ||
| #[ApiFilter(SearchFilter::class, properties: ['camp'])] | ||
| class Period extends BaseEntity implements BelongsToCampInterface { | ||
|
|
@@ -38,7 +52,12 @@ class Period extends BaseEntity implements BelongsToCampInterface { | |
| * @ORM\OneToMany(targetEntity="Day", mappedBy="period", orphanRemoval=true) | ||
| * @ORM\OrderBy({"dayOffset": "ASC"}) | ||
| */ | ||
| #[ApiProperty(writable: false, example: '["/days/1a2b3c4d"]')] | ||
| #[ApiProperty( | ||
| readableLink: false, | ||
pmattmann marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| writable: false, | ||
| example: '/days?period=/periods/1a2b3c4d' | ||
| )] | ||
| #[Groups(['read'])] | ||
| public Collection $days; | ||
|
|
||
| /** | ||
|
|
@@ -66,8 +85,8 @@ class Period extends BaseEntity implements BelongsToCampInterface { | |
| * @ORM\ManyToOne(targetEntity="Camp", inversedBy="periods") | ||
| * @ORM\JoinColumn(nullable=false) | ||
| */ | ||
| #[ApiProperty(example: '/camps/1a2b3c4d')] | ||
| #[Groups(['Default'])] | ||
| #[ApiProperty(readableLink: false, example: '/camps/1a2b3c4d')] | ||
pmattmann marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| #[Groups(['read'])] | ||
| public ?Camp $camp = null; | ||
|
|
||
| /** | ||
|
|
@@ -79,7 +98,7 @@ class Period extends BaseEntity implements BelongsToCampInterface { | |
| */ | ||
| #[Assert\NotBlank] | ||
| #[ApiProperty(example: 'Hauptlager')] | ||
| #[Groups(['Default', 'period:update'])] | ||
| #[Groups(['Properties:read', 'Properties:write'])] | ||
pmattmann marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| public ?string $description = null; | ||
|
|
||
| /** | ||
|
|
@@ -95,7 +114,7 @@ class Period extends BaseEntity implements BelongsToCampInterface { | |
| */ | ||
| #[Assert\LessThanOrEqual(propertyPath: 'end')] | ||
| #[ApiProperty(example: '2022-01-01', openapiContext: ['format' => 'date'])] | ||
| #[Groups(['Default', 'period:update'])] | ||
| #[Groups(['Properties:read', 'Properties:write'])] | ||
pmattmann marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| public ?DateTimeInterface $start = null; | ||
|
|
||
| /** | ||
|
|
@@ -106,7 +125,7 @@ class Period extends BaseEntity implements BelongsToCampInterface { | |
| */ | ||
| #[Assert\GreaterThanOrEqual(propertyPath: 'start')] | ||
| #[ApiProperty(example: '2022-01-08', openapiContext: ['format' => 'date'])] | ||
| #[Groups(['Default', 'period:update'])] | ||
| #[Groups(['Properties:read', 'Properties:write'])] | ||
pmattmann marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| public ?DateTimeInterface $end = null; | ||
|
|
||
| public function __construct() { | ||
|
|
@@ -115,6 +134,23 @@ public function __construct() { | |
| $this->materialItems = new ArrayCollection(); | ||
| } | ||
|
|
||
| #[ApiProperty( | ||
| readableLink: true, | ||
| example: '[{ "dayOffset": 0, "number": 1 }]' | ||
| )] | ||
| #[SerializedName('days')] | ||
| #[Groups('Period:Days')] | ||
| public function getEmbeddedDays(): Collection { | ||
| return $this->days; | ||
| } | ||
|
|
||
| #[ApiProperty(readableLink: true)] | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bei
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bei den /**
* @return Day[]
*/
#[ApiProperty(readableLink: true)]
#[SerializedName('days')]
#[Groups('Period:Days')]
public function getEmbeddedDays(): array {
return $this->days->getValues();
}
#[ApiProperty(readableLink: true)]
#[SerializedName('camp')]
#[Groups(['Period:Camp'])]
public function getEmbeddedCamp(): ?Camp {
return $this->camp;
} |
||
| #[SerializedName('camp')] | ||
| #[Groups(['Period:Camp'])] | ||
| public function getEmbeddedCamp(): ?Camp { | ||
| return $this->camp; | ||
| } | ||
|
|
||
| public function getCamp(): ?Camp { | ||
| return $this->camp; | ||
| } | ||
|
|
||

Uh oh!
There was an error while loading. Please reload this page.