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

Commit fd1953f

Browse files
nicholsp2Teddy Roncin
andauthored
Feature/edt (#25)
* feat: First part of the exposition of the Asso Event and UE entities * feat: Added a new entry point on user to retrieve said user's schedule * fix: code modification to comply with pull request remarks removal of dead code / switched group name from user:read:one:edt to user-edt:read:one / added documentation * fix(getEdtController-SemesterRepository): removed an unused overload on getSemesterOfDate / added documentation * refactor(Asso-Event-Translation-UE): Revert of unwanted files * fix(UE): fixes a bug created by a conflic during revert * :bug: (User) fixed entity User /users routes will now return all fields, even if they are empty (in this case there content will be null) Closes #28 Co-authored-by: Teddy Roncin <[email protected]>
1 parent 5b93150 commit fd1953f

File tree

4 files changed

+82
-0
lines changed

4 files changed

+82
-0
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
3+
namespace App\Controller;
4+
5+
use App\Entity\Semester;
6+
use App\Entity\User;
7+
use DateTime;
8+
use Doctrine\ORM\EntityManagerInterface;
9+
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
10+
11+
// This class is a controller that removes expired courses from the user's EDT
12+
class GetEDTController extends AbstractController
13+
{
14+
private $manager;
15+
16+
public function __construct(EntityManagerInterface $manager)
17+
{
18+
$this->manager = $manager;
19+
}
20+
21+
public function __invoke(User $data): User
22+
{
23+
$repository = $this->getDoctrine()->getRepository(Semester::class);
24+
$currentSemesterCode = $repository->getSemesterOfDate(new DateTime())->getCode();
25+
26+
$nbCourses = \count($data->getCourses());
27+
28+
for ($i = $nbCourses - 1; $i >= 0; --$i) {
29+
if ($data->getCourses()[$i]->getSemester()->getCode() !== $currentSemesterCode) {
30+
//altering $data doesn't alter the database as it is only a representation
31+
unset($data->getCourses()[$i]);
32+
}
33+
}
34+
35+
return $data;
36+
}
37+
}

src/Entity/UE.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@ class UE
3636
* @Assert\Length(min=1, max=10)
3737
* @Assert\Regex("/^[a-zA-Z]{1,5}[0-9]{1,2}$/")
3838
*/
39+
#[Groups([
40+
'ue:read:one',
41+
'ue:read:some',
42+
'user-edt:read:one',
43+
])]
3944
private $code;
4045

4146
/**

src/Entity/UECourse.php

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

@@ -34,6 +35,9 @@ class UECourse
3435
*
3536
* @ORM\ManyToOne(targetEntity=UE::class, inversedBy="courses")
3637
*/
38+
#[Groups([
39+
'user-edt:read:one',
40+
])]
3741
private $UE;
3842

3943
/**
@@ -44,6 +48,9 @@ class UECourse
4448
* @Assert\Type("string")
4549
* @Assert\Choice({"Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"})
4650
*/
51+
#[Groups([
52+
'user-edt:read:one',
53+
])]
4754
private $day;
4855

4956
/**
@@ -53,6 +60,9 @@ class UECourse
5360
*
5461
* @Assert\Time
5562
*/
63+
#[Groups([
64+
'user-edt:read:one',
65+
])]
5666
private $startHour;
5767

5868
/**
@@ -62,6 +72,9 @@ class UECourse
6272
*
6373
* @Assert\Time
6474
*/
75+
#[Groups([
76+
'user-edt:read:one',
77+
])]
6578
private $endHour;
6679

6780
/**
@@ -72,6 +85,9 @@ class UECourse
7285
* @Assert\Type("string")
7386
* @Assert\Choice({"A", "B"})
7487
*/
88+
#[Groups([
89+
'user-edt:read:one',
90+
])]
7591
private $week;
7692

7793
/**
@@ -80,6 +96,9 @@ class UECourse
8096
* @Assert\Type("string")
8197
* @Assert\Choice({"CM", "TD", "TP"})
8298
*/
99+
#[Groups([
100+
'user-edt:read:one',
101+
])]
83102
private $type;
84103

85104
/**
@@ -90,6 +109,9 @@ class UECourse
90109
* @Assert\Type("string")
91110
* @Assert\Length(min=1, max=50)
92111
*/
112+
#[Groups([
113+
'user-edt:read:one',
114+
])]
93115
private $room;
94116

95117
/**

src/Entity/User.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace App\Entity;
44

55
use ApiPlatform\Core\Annotation\ApiResource;
6+
use App\Controller\GetEDTController;
67
use App\Controller\SoftDeleteController;
78
use App\Repository\UserRepository;
89
use Doctrine\Common\Collections\ArrayCollection;
@@ -27,6 +28,9 @@
2728
'security' => "is_granted('ROLE_USER')",
2829
'pagination_items_per_page' => 10,
2930
],
31+
normalizationContext: [
32+
'skip_null_values' => false,
33+
],
3034
collectionOperations: [
3135
'get' => [
3236
'normalization_context' => [
@@ -42,6 +46,17 @@
4246
'skip_null_values' => false,
4347
],
4448
],
49+
'edt' => [
50+
'method' => 'GET',
51+
'path' => '/user/{id}/edt',
52+
'controller' => GetEDTController::class,
53+
'normalization_context' => [
54+
'groups' => ['user-edt:read:one'],
55+
],
56+
'openapi_context' => [
57+
'summary' => 'retrieves a user\'s schedule',
58+
],
59+
],
4560
'delete' => [
4661
'controller' => SoftDeleteController::class,
4762
'security' => "is_granted('ROLE_ADMIN')",
@@ -326,6 +341,9 @@ class User implements UserInterface
326341
*
327342
* @ORM\ManyToMany(targetEntity=UECourse::class, mappedBy="students")
328343
*/
344+
#[Groups([
345+
'user-edt:read:one',
346+
])]
329347
private $courses;
330348

331349
public function __construct()

0 commit comments

Comments
 (0)