Skip to content

Commit 3b2b8b9

Browse files
committed
Internal: Refactor API Resource definitions for CTool and CToolIntro
1 parent 98cd3c7 commit 3b2b8b9

File tree

2 files changed

+31
-4
lines changed

2 files changed

+31
-4
lines changed

src/CourseBundle/Entity/CTool.php

+4-3
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,12 @@
2828

2929
#[ApiResource(
3030
operations: [
31-
new GetCollection(),
31+
new GetCollection(
32+
output: CourseTool::class,
33+
provider: CToolStateProvider::class,
34+
),
3235
],
3336
normalizationContext: ['groups' => ['ctool:read']],
34-
output: CourseTool::class,
35-
provider: CToolStateProvider::class,
3637
)]
3738
#[ORM\Table(name: 'c_tool')]
3839
#[ORM\Index(columns: ['c_id'], name: 'course')]

src/CourseBundle/Entity/CToolIntro.php

+27-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,22 @@
2626
use Symfony\Component\Uid\Uuid;
2727
use Symfony\Component\Validator\Constraints as Assert;
2828

29-
#[ApiResource(operations: [new Get(security: 'is_granted(\'VIEW\', object)'), new Put(security: 'is_granted(\'EDIT\', object)'), new Delete(security: 'is_granted(\'DELETE\', object)'), new GetCollection(security: 'is_granted(\'ROLE_USER\')'), new Post(securityPostDenormalize: 'is_granted(\'CREATE\', object)')], security: 'is_granted(\'ROLE_ADMIN\') or is_granted(\'ROLE_CURRENT_COURSE_TEACHER\')', denormalizationContext: ['groups' => ['c_tool_intro:write']], normalizationContext: ['groups' => ['c_tool_intro:read']])]
29+
#[ApiResource(
30+
operations: [
31+
new Get(security: "is_granted('VIEW', object)"),
32+
new Put(security: "is_granted('EDIT', object)"),
33+
new Delete(security: "is_granted('DELETE', object)"),
34+
new GetCollection(security: "is_granted('ROLE_USER')"),
35+
new Post(securityPostDenormalize: "is_granted('CREATE', object)"),
36+
],
37+
normalizationContext: [
38+
'groups' => ['c_tool_intro:read'],
39+
],
40+
denormalizationContext: [
41+
'groups' => ['c_tool_intro:write'],
42+
],
43+
security: "is_granted('ROLE_ADMIN') or is_granted('ROLE_CURRENT_COURSE_TEACHER')",
44+
)]
3045
#[ORM\Table(name: 'c_tool_intro')]
3146
#[ORM\Entity(repositoryClass: CToolIntroRepository::class)]
3247
#[ApiFilter(filterClass: SearchFilter::class, properties: ['courseTool' => 'exact'])]
@@ -39,51 +54,62 @@ class CToolIntro extends AbstractResource implements ResourceInterface, Resource
3954
#[ORM\Id]
4055
#[ORM\GeneratedValue]
4156
protected ?int $iid = null;
57+
4258
#[Assert\NotNull]
4359
#[Groups(['c_tool_intro:read', 'c_tool_intro:write'])]
4460
#[ORM\Column(name: 'intro_text', type: 'text', nullable: false)]
4561
protected string $introText;
62+
4663
#[Assert\NotNull]
4764
#[Groups(['c_tool_intro:read', 'c_tool_intro:write'])]
4865
#[ORM\ManyToOne(targetEntity: CTool::class)]
4966
#[ORM\JoinColumn(name: 'c_tool_id', referencedColumnName: 'iid', nullable: false, onDelete: 'CASCADE')]
5067
protected CTool $courseTool;
68+
5169
public function __toString(): string
5270
{
5371
return $this->getIntroText();
5472
}
73+
5574
public function getIid(): ?int
5675
{
5776
return $this->iid;
5877
}
78+
5979
public function getCourseTool(): CTool
6080
{
6181
return $this->courseTool;
6282
}
83+
6384
public function setCourseTool(CTool $courseTool): self
6485
{
6586
$this->courseTool = $courseTool;
6687

6788
return $this;
6889
}
90+
6991
public function setIntroText(string $introText): self
7092
{
7193
$this->introText = $introText;
7294

7395
return $this;
7496
}
97+
7598
public function getIntroText(): string
7699
{
77100
return $this->introText;
78101
}
102+
79103
public function getResourceIdentifier(): int|Uuid
80104
{
81105
return $this->getIid();
82106
}
107+
83108
public function getResourceName(): string
84109
{
85110
return $this->getCourseTool()->getTitle();
86111
}
112+
87113
public function setResourceName(string $name): self
88114
{
89115
return $this;

0 commit comments

Comments
 (0)