Skip to content
This repository was archived by the owner on Apr 3, 2023. It is now read-only.

Commit 491e734

Browse files
ThomasRitainenicholsp2Teddy Roncin
authored
feat: First part of the exposition of the Asso, Event, and UE entities (#24)
* feat: First part of the exposition of the Asso Event and UE entities * 🐛 (Asso) Fixed a few problems of PR#24 createdAt and keywords are now exposed. Fixed import errors. Linted a space. Merged both class annotations in the same #[]. Added a sort based on the asso name. Added a filter on keywords * 🐛 (Routes /assos) Polished the PR null values will now be returned in routes /assos, /events and /ues. Descriptions are now returned in route GET /assos (short description) and GET /assos/{id} (long description). Memberships and membership count are now exposed. * 🐛 (/ues and /events) These files should have been in the previous PR. null values were not sent set attribute "skip_null_values" to false in the exposition of /ues and /events * 🐛 (/ues, /events) Polishing Added security for /ues and /events routes. Parameters of ApiResource are now in the right order for files UE, Event and Asso. Changed filter for UE searching from exact to partial * ⬆️ (PHP) upgrading from PHP 8.0 to PHP 8.1 This may be the reason why build are failing in PR#24 * 🐛 (php version) changed php version for tests * 🐛 (composer.lock) regenerated composer.lock * 🚨 (Asso.php and Event.php) Linted the whole project Co-authored-by: pierre <[email protected]> Co-authored-by: Teddy Roncin <[email protected]>
1 parent fd1953f commit 491e734

File tree

10 files changed

+1526
-1210
lines changed

10 files changed

+1526
-1210
lines changed

.php-version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
8.0
1+
8.1

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ dist: focal
33

44
language: php
55
php:
6-
- 8.0
6+
- 8.1
77

88
cache:
99
directories:

composer.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,11 @@
6666
"preferred-install": {
6767
"*": "dist"
6868
},
69-
"sort-packages": true
69+
"sort-packages": true,
70+
"allow-plugins": {
71+
"symfony/flex": true,
72+
"symfony/runtime": true
73+
}
7074
},
7175
"autoload": {
7276
"psr-4": {

composer.lock

Lines changed: 1270 additions & 1207 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Entity/Asso.php

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,68 @@
22

33
namespace App\Entity;
44

5+
use ApiPlatform\Core\Annotation\ApiFilter;
6+
use ApiPlatform\Core\Annotation\ApiResource;
7+
use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\SearchFilter;
8+
use App\Controller\SoftDeleteController;
59
use App\Repository\AssoRepository;
610
use DateTime;
711
use DateTimeInterface;
812
use Doctrine\Common\Collections\ArrayCollection;
913
use Doctrine\Common\Collections\Collection;
1014
use Doctrine\ORM\Mapping as ORM;
1115
use Symfony\Bridge\Doctrine\IdGenerator\UuidGenerator;
16+
use Symfony\Component\Serializer\Annotation\Groups;
1217
use Symfony\Component\Serializer\Annotation\SerializedName;
1318
use Symfony\Component\Uid\Uuid;
1419
use Symfony\Component\Validator\Constraints as Assert;
1520

1621
/**
22+
* The main entity that represents all Assos.
23+
*
1724
* @ORM\Entity(repositoryClass=AssoRepository::class)
1825
* @ORM\Table(name="assos")
1926
*/
27+
#[
28+
ApiResource(
29+
collectionOperations: [
30+
'get' => [
31+
'normalization_context' => [
32+
'groups' => ['asso:read:some'],
33+
],
34+
],
35+
],
36+
itemOperations: [
37+
'get' => [
38+
'normalization_context' => [
39+
'groups' => ['asso:read:one'],
40+
],
41+
],
42+
'delete' => [
43+
'controller' => SoftDeleteController::class,
44+
'security' => "is_granted('ROLE_ADMIN')",
45+
],
46+
'patch' => [
47+
'denormalization_context' => [
48+
'groups' => ['asso:write:update'],
49+
],
50+
'normalization_context' => [
51+
'groups' => ['asso:read:one'],
52+
],
53+
'security' => "object == user or is_granted('ROLE_ADMIN')",
54+
],
55+
],
56+
shortName: 'asso',
57+
attributes: [
58+
'pagination_items_per_page' => 10,
59+
],
60+
normalizationContext: [
61+
'skip_null_values' => false,
62+
],
63+
order: ['name'],
64+
),
65+
ApiFilter(SearchFilter::class, properties: ['name' => 'partial', 'keywords' => 'exact']),
66+
]
2067
class Asso
2168
{
2269
/**
@@ -27,6 +74,10 @@ class Asso
2774
*
2875
* @Assert\Uuid
2976
*/
77+
#[Groups([
78+
'asso:read:one',
79+
'asso:read:some',
80+
])]
3081
private $id;
3182

3283
/**
@@ -46,6 +97,10 @@ class Asso
4697
* @Assert\Type("string")
4798
* @Assert\Length(min=1, max=100)
4899
*/
100+
#[Groups([
101+
'asso:read:one',
102+
'asso:read:some',
103+
])]
49104
private $name;
50105

51106
/**
@@ -54,6 +109,9 @@ class Asso
54109
* @ORM\ManyToOne(targetEntity=Translation::class, cascade={"persist", "remove"})
55110
*/
56111
#[SerializedName('descriptionShort')]
112+
#[Groups([
113+
'asso:read:some',
114+
])]
57115
private $descriptionShortTranslation;
58116

59117
/**
@@ -62,6 +120,9 @@ class Asso
62120
* @ORM\ManyToOne(targetEntity=Translation::class, cascade={"persist", "remove"})
63121
*/
64122
#[SerializedName('description')]
123+
#[Groups([
124+
'asso:read:one',
125+
])]
65126
private $descriptionTranslation;
66127

67128
/**
@@ -73,6 +134,9 @@ class Asso
73134
* @Assert\Length(min=1, max=100)
74135
* @Assert\Email
75136
*/
137+
#[Groups([
138+
'asso:read:one',
139+
])]
76140
private $mail;
77141

78142
/**
@@ -84,6 +148,9 @@ class Asso
84148
* @Assert\Length(min=0, max=30)
85149
* @Assert\Regex("/^0[0-9]{9}$/")
86150
*/
151+
#[Groups([
152+
'asso:read:one',
153+
])]
87154
private $phoneNumber;
88155

89156
/**
@@ -95,6 +162,9 @@ class Asso
95162
* @Assert\Length(min=0, max=100)
96163
* @Assert\Url
97164
*/
165+
#[Groups([
166+
'asso:read:one',
167+
])]
98168
private $website;
99169

100170
/**
@@ -105,13 +175,20 @@ class Asso
105175
* @Assert\Type("string")
106176
* @Assert\Length(min=0, max=100)
107177
*/
178+
#[Groups([
179+
'asso:read:some',
180+
'asso:read:one',
181+
])]
108182
private $logo;
109183

110184
/**
111185
* @ORM\Column(type="datetime")
112186
*
113187
* @Assert\Type("\DateTimeInterface")
114188
*/
189+
#[Groups([
190+
'asso:read:one',
191+
])]
115192
private $createdAt;
116193

117194
/**
@@ -138,6 +215,9 @@ class Asso
138215
* inverseJoinColumns={@ORM\JoinColumn(name="keyword", referencedColumnName="name")}
139216
* )
140217
*/
218+
#[Groups([
219+
'asso:read:one',
220+
])]
141221
private $keywords;
142222

143223
/**
@@ -152,6 +232,9 @@ class Asso
152232
*
153233
* @ORM\ManyToMany(targetEntity=Event::class, mappedBy="assos")
154234
*/
235+
#[Groups([
236+
'asso:read:one',
237+
])]
155238
private $events;
156239

157240
/**
@@ -166,6 +249,9 @@ class Asso
166249
*
167250
* @ORM\OneToMany(targetEntity=AssoMembership::class, mappedBy="asso", orphanRemoval=true)
168251
*/
252+
#[Groups([
253+
'asso:read:one',
254+
])]
169255
private $assoMemberships;
170256

171257
public function __construct()
@@ -464,4 +550,12 @@ public function removeAssoMembership(AssoMembership $assoMember): self
464550

465551
return $this;
466552
}
553+
554+
#[Groups([
555+
'asso:read:some',
556+
])]
557+
public function getMembershipsCount(): int
558+
{
559+
return $this->assoMemberships->count();
560+
}
467561
}

src/Entity/AssoKeyword.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use Doctrine\Common\Collections\ArrayCollection;
77
use Doctrine\Common\Collections\Collection;
88
use Doctrine\ORM\Mapping as ORM;
9+
use Symfony\Component\Serializer\Annotation\Groups;
910
use Symfony\Component\Validator\Constraints as Assert;
1011

1112
/**
@@ -22,6 +23,9 @@ class AssoKeyword
2223
* @Assert\Length(min=1, max=30)
2324
* @Assert\Regex("/^[a-z]{1,30}$/")
2425
*/
26+
#[Groups([
27+
'asso:read:one',
28+
])]
2529
private $name;
2630

2731
/**

src/Entity/AssoMembership.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use Doctrine\Common\Collections\Collection;
1010
use Doctrine\ORM\Mapping as ORM;
1111
use Symfony\Bridge\Doctrine\IdGenerator\UuidGenerator;
12+
use Symfony\Component\Serializer\Annotation\Groups;
1213
use Symfony\Component\Uid\Uuid;
1314
use Symfony\Component\Validator\Constraints as Assert;
1415

@@ -34,6 +35,9 @@ class AssoMembership
3435
* @ORM\ManyToOne(targetEntity=User::class, inversedBy="assoMembership")
3536
* @ORM\JoinColumn(nullable=false)
3637
*/
38+
#[Groups([
39+
'asso:read:one',
40+
])]
3741
private $user;
3842

3943
/**

0 commit comments

Comments
 (0)