-
-
Notifications
You must be signed in to change notification settings - Fork 199
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Allow users to download formations * [Api] Formation content endpoints * Fix review
- Loading branch information
Showing
4 changed files
with
80 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?php | ||
|
||
namespace App\Controller\Api; | ||
|
||
use App\Entity\Adherent; | ||
use App\Entity\AdherentFormation\Formation; | ||
use Doctrine\ORM\EntityManagerInterface; | ||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; | ||
|
||
abstract class AbstractFormationContentController extends AbstractController | ||
{ | ||
public function __construct(private readonly EntityManagerInterface $entityManager) | ||
{ | ||
} | ||
|
||
protected function printFormation(Formation $formation): void | ||
{ | ||
/** @var Adherent $adherent */ | ||
$adherent = $this->getUser(); | ||
|
||
if ( | ||
!$adherent instanceof Adherent | ||
|| $this->isGranted('ROLE_OAUTH_SCOPE_JEMENGAGE_ADMIN') | ||
) { | ||
return; | ||
} | ||
|
||
if ($formation->addPrintByAdherent($adherent)) { | ||
$this->entityManager->flush(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
|
||
namespace App\Controller\Api; | ||
|
||
use App\Entity\AdherentFormation\Formation; | ||
use Symfony\Component\HttpFoundation\Response; | ||
use Symfony\Component\Serializer\SerializerInterface; | ||
|
||
class FormationLinkController extends AbstractFormationContentController | ||
{ | ||
public function __invoke( | ||
SerializerInterface $serializer, | ||
Formation $formation, | ||
): Response { | ||
if (!$formation->isLinkContent()) { | ||
throw $this->createNotFoundException('Formation has no link'); | ||
} | ||
|
||
$this->printFormation($formation); | ||
|
||
return $this->json( | ||
$formation, | ||
Response::HTTP_OK, | ||
[], | ||
['groups' => ['formation_read_link']] | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters