|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
/* |
|
6
|
|
|
* This file is part of the zibios/sharep. |
|
7
|
|
|
* |
|
8
|
|
|
* (c) Zbigniew Ślązak |
|
9
|
|
|
*/ |
|
10
|
|
|
|
|
11
|
|
|
namespace App\Entity\Parking; |
|
12
|
|
|
|
|
13
|
|
|
use ApiPlatform\Core\Annotation as OA; |
|
14
|
|
|
use App\Entity\EntityInterface; |
|
15
|
|
|
use App\Entity\GetMemberInterface; |
|
16
|
|
|
use App\Entity\Traits; |
|
17
|
|
|
use App\Enum\Entity\ReservationTypeEnum; |
|
18
|
|
|
use Doctrine\ORM\Mapping as ORM; |
|
19
|
|
|
use PascalDeVink\ShortUuid\ShortUuid; |
|
20
|
|
|
use Symfony\Bridge\Doctrine\Validator\Constraints as OrmAssert; |
|
21
|
|
|
use Symfony\Component\Serializer\Annotation as Serializer; |
|
22
|
|
|
use Symfony\Component\Validator\Constraints as Assert; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* @ORM\Entity(repositoryClass="App\Repository\Entity\Parking\ReservationRepository") |
|
26
|
|
|
* @ORM\Table( |
|
27
|
|
|
* name="parking_reservations", |
|
28
|
|
|
* uniqueConstraints={@ORM\UniqueConstraint(name="parking_reservations_date_member_uidx", columns={"date", "member_id"})} |
|
29
|
|
|
* ) |
|
30
|
|
|
* @OrmAssert\UniqueEntity(fields={"date", "member"}, errorPath="member", message="Date for Member already exist") |
|
31
|
|
|
* @OA\ApiResource( |
|
32
|
|
|
* input={"class"="\App\Api\Dto\Parking\ReservationInputDto"}, |
|
33
|
|
|
* normalizationContext={"groups"={"get"}}, |
|
34
|
|
|
* itemOperations={ |
|
35
|
|
|
* "get"={ |
|
36
|
|
|
* "access_control"="is_granted('PARKING_RESERVATION_READ')" |
|
37
|
|
|
* }, |
|
38
|
|
|
* "delete"={ |
|
39
|
|
|
* "controller"="\App\Controller\Api\Parking\ReservationDeleteAction", |
|
40
|
|
|
* "access_control"="is_granted('PARKING_RESERVATION_DELETE', object)" |
|
41
|
|
|
* }, |
|
42
|
|
|
* "put"={ |
|
43
|
|
|
* "denormalization_context"={"groups"={"put"}}, |
|
44
|
|
|
* "access_control"="is_granted('PARKING_RESERVATION_UPDATE', object) and is_granted('PARKING_RESERVATION_UPDATE', previous_object)" |
|
45
|
|
|
* } |
|
46
|
|
|
* }, |
|
47
|
|
|
* collectionOperations={ |
|
48
|
|
|
* "get"={ |
|
49
|
|
|
* "access_control"="is_granted('PARKING_RESERVATION_READ')" |
|
50
|
|
|
* }, |
|
51
|
|
|
* "post"={ |
|
52
|
|
|
* "denormalization_context"={"groups"={"post"}}, |
|
53
|
|
|
* "access_control"="is_granted('PARKING_RESERVATION_CREATE', object)" |
|
54
|
|
|
* } |
|
55
|
|
|
* } |
|
56
|
|
|
* ) |
|
57
|
|
|
*/ |
|
58
|
|
|
class Reservation implements EntityInterface, GetMemberInterface |
|
59
|
|
|
{ |
|
60
|
|
|
use Traits\PropertyIdGeneratedTrait; |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* @var \DateTimeImmutable |
|
64
|
|
|
* @ORM\Column(name="date", type="date_immutable", nullable=false) |
|
65
|
|
|
* |
|
66
|
|
|
* @Assert\Date() |
|
67
|
|
|
* |
|
68
|
|
|
* @Serializer\Groups({"get"}) |
|
69
|
|
|
* @OA\ApiProperty( |
|
70
|
|
|
* attributes={ |
|
71
|
|
|
* "swagger_context"={"type"="string", "format"="date", "example"="2000-01-01"}, |
|
72
|
|
|
* "normalization_context"={"date_format"="Y-m-d", "datetime_format"="Y-m-d"}, |
|
73
|
|
|
* } |
|
74
|
|
|
* ) |
|
75
|
|
|
* @OA\ApiFilter( |
|
76
|
|
|
* ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\DateFilter::class, |
|
77
|
|
|
* strategy="ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\DateFilter::INCLUDE_NULL_BEFORE" |
|
78
|
|
|
* ) |
|
79
|
|
|
* @OA\ApiFilter( |
|
80
|
|
|
* ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\SearchFilter::class, |
|
81
|
|
|
* strategy="exact" |
|
82
|
|
|
* ) |
|
83
|
|
|
*/ |
|
84
|
|
|
private $date; |
|
85
|
|
|
|
|
86
|
|
|
/** |
|
87
|
|
|
* @var string |
|
88
|
|
|
* @ORM\Column(name="type", type="string", length=50, nullable=false) |
|
89
|
|
|
* |
|
90
|
|
|
* @Assert\NotBlank() |
|
91
|
|
|
* @Assert\Type("string") |
|
92
|
|
|
* @Assert\Length(min="1", max="50") |
|
93
|
|
|
* |
|
94
|
|
|
* @Serializer\Groups({"get"}) |
|
95
|
|
|
* @OA\ApiProperty( |
|
96
|
|
|
* attributes={ |
|
97
|
|
|
* "swagger_context"={"type"="string", "enum"={"REVOKED","ASSIGNED"}, "example"="REVOKED"}, |
|
98
|
|
|
* } |
|
99
|
|
|
* ) |
|
100
|
|
|
* @OA\ApiFilter( |
|
101
|
|
|
* ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\SearchFilter::class, |
|
102
|
|
|
* strategy="exact" |
|
103
|
|
|
* ) |
|
104
|
|
|
*/ |
|
105
|
|
|
private $type; |
|
106
|
|
|
|
|
107
|
|
|
/** |
|
108
|
|
|
* @var int |
|
109
|
|
|
* @ORM\Column(name="places", type="integer", nullable=false) |
|
110
|
|
|
* |
|
111
|
|
|
* @Assert\PositiveOrZero() |
|
112
|
|
|
* |
|
113
|
|
|
* @Serializer\Groups({"get"}) |
|
114
|
|
|
* @OA\ApiProperty( |
|
115
|
|
|
* attributes={ |
|
116
|
|
|
* "swagger_context"={"type"="integer", "example"=1}, |
|
117
|
|
|
* } |
|
118
|
|
|
* ) |
|
119
|
|
|
* @OA\ApiFilter( |
|
120
|
|
|
* ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\RangeFilter::class |
|
121
|
|
|
* ) |
|
122
|
|
|
* @OA\ApiFilter( |
|
123
|
|
|
* ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\SearchFilter::class, |
|
124
|
|
|
* strategy="exact" |
|
125
|
|
|
* ) |
|
126
|
|
|
*/ |
|
127
|
|
|
private $places; |
|
128
|
|
|
|
|
129
|
|
|
//------------------------------------------------------------------------------------------- |
|
130
|
|
|
|
|
131
|
|
|
/** |
|
132
|
|
|
* @var Member |
|
133
|
|
|
* @ORM\ManyToOne(targetEntity="App\Entity\Parking\Member") |
|
134
|
|
|
* @ORM\JoinColumn(name="member_id", referencedColumnName="id") |
|
135
|
|
|
* |
|
136
|
|
|
* @Assert\NotNull() |
|
137
|
|
|
* |
|
138
|
|
|
* @Serializer\Groups({"get"}) |
|
139
|
|
|
* @OA\ApiSubresource() |
|
140
|
|
|
* @OA\ApiProperty( |
|
141
|
|
|
* attributes={ |
|
142
|
|
|
* "swagger_context"={"type"="string", "example"="id"}, |
|
143
|
|
|
* } |
|
144
|
|
|
* ) |
|
145
|
|
|
* @OA\ApiFilter( |
|
146
|
|
|
* ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\SearchFilter::class, |
|
147
|
|
|
* strategy="exact" |
|
148
|
|
|
* ) |
|
149
|
|
|
* @OA\ApiFilter( |
|
150
|
|
|
* ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\SearchFilter::class, |
|
151
|
|
|
* strategy="exact", |
|
152
|
|
|
* properties={"member.id"} |
|
153
|
|
|
* ) |
|
154
|
|
|
*/ |
|
155
|
|
|
protected $member; |
|
156
|
|
|
|
|
157
|
|
|
//------------------------------------------------------------------------------------------- |
|
158
|
|
|
|
|
159
|
1 |
|
public function __construct(Member $member, \DateTimeImmutable $date, int $places, ReservationTypeEnum $type) |
|
160
|
|
|
{ |
|
161
|
1 |
|
$this->id = ShortUuid::uuid4(); |
|
162
|
1 |
|
$this->member = $member; |
|
163
|
1 |
|
$this->date = $date; |
|
164
|
1 |
|
$this->setPlaces($places); |
|
165
|
1 |
|
$this->setType($type); |
|
166
|
1 |
|
} |
|
167
|
|
|
|
|
168
|
|
|
//------------------------------------------------------------------------------------------- |
|
169
|
|
|
|
|
170
|
1 |
|
public function getDate(): \DateTimeImmutable |
|
171
|
|
|
{ |
|
172
|
1 |
|
return $this->date; |
|
173
|
|
|
} |
|
174
|
|
|
|
|
175
|
1 |
|
public function getMember(): Member |
|
176
|
|
|
{ |
|
177
|
1 |
|
return $this->member; |
|
178
|
|
|
} |
|
179
|
|
|
|
|
180
|
1 |
|
public function getPlaces(): int |
|
181
|
|
|
{ |
|
182
|
1 |
|
return $this->places; |
|
183
|
|
|
} |
|
184
|
|
|
|
|
185
|
1 |
|
public function setPlaces(int $places): self |
|
186
|
|
|
{ |
|
187
|
1 |
|
$this->places = $places; |
|
188
|
|
|
|
|
189
|
1 |
|
return $this; |
|
190
|
|
|
} |
|
191
|
|
|
|
|
192
|
1 |
|
public function getType(): ReservationTypeEnum |
|
193
|
|
|
{ |
|
194
|
1 |
|
return new ReservationTypeEnum($this->type); |
|
195
|
|
|
} |
|
196
|
|
|
|
|
197
|
1 |
|
public function setType(ReservationTypeEnum $type): self |
|
198
|
|
|
{ |
|
199
|
1 |
|
$this->type = $type->getValue(); |
|
200
|
|
|
|
|
201
|
1 |
|
return $this; |
|
202
|
|
|
} |
|
203
|
|
|
} |
|
204
|
|
|
|