-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added endpoints to join and leave events
- Loading branch information
Felix Ruf
committed
Jan 10, 2024
1 parent
78649cc
commit a7d31b8
Showing
7 changed files
with
141 additions
and
3 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
61 changes: 61 additions & 0 deletions
61
src/Mealz/MealBundle/Controller/EventParticipationController.php
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,61 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Mealz\MealBundle\Controller; | ||
|
||
use App\Mealz\MealBundle\Entity\Day; | ||
use App\Mealz\MealBundle\Event\EventParticipationUpdateEvent; | ||
use App\Mealz\MealBundle\Service\EventParticipationService; | ||
use Symfony\Component\EventDispatcher\EventDispatcherInterface; | ||
use Symfony\Component\HttpFoundation\JsonResponse; | ||
|
||
/** | ||
* @Security("is_granted('ROLE_USER')") | ||
*/ | ||
class EventParticipationController extends BaseController | ||
{ | ||
|
||
private EventDispatcherInterface $eventDispatcher; | ||
private EventParticipationService $eventParticipationService; | ||
Check warning on line 20 in src/Mealz/MealBundle/Controller/EventParticipationController.php
|
||
|
||
public function __construct( | ||
EventDispatcherInterface $eventDispatcher, | ||
EventParticipationService $eventParticipationService | ||
Check warning on line 24 in src/Mealz/MealBundle/Controller/EventParticipationController.php
|
||
) { | ||
$this->eventDispatcher = $eventDispatcher; | ||
$this->eventParticipationService = $eventParticipationService; | ||
} | ||
|
||
public function join(Day $day): JsonResponse | ||
{ | ||
$profile = $this->getProfile(); | ||
if (null === $profile) { | ||
return new JsonResponse(['messasge' => '801: User is not allowed to join'], 403); | ||
} | ||
|
||
$eventParticipation = $this->eventParticipationService->join($profile, $day); | ||
if (null === $eventParticipation) { | ||
return new JsonResponse(['messasge' => '802: User could not join the event'], 500); | ||
} | ||
|
||
$this->eventDispatcher->dispatch(new EventParticipationUpdateEvent($eventParticipation)); | ||
return new JsonResponse(['isParticipating' => true], 200); | ||
} | ||
|
||
public function leave(Day $day): JsonResponse | ||
{ | ||
$profile = $this->getProfile(); | ||
if (null === $profile) { | ||
return new JsonResponse(['messasge' => '801: User is not allowed to leave'], 403); | ||
} | ||
|
||
$eventParticipation = $this->eventParticipationService->leave($profile, $day); | ||
if (null === $eventParticipation) { | ||
return new JsonResponse(['messasge' => '802: User could not leave the event'], 500); | ||
} | ||
|
||
$this->eventDispatcher->dispatch(new EventParticipationUpdateEvent($eventParticipation)); | ||
return new JsonResponse(['isParticipating' => false], 200); | ||
} | ||
} |
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
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
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