|
@@ -9,12 +9,14 @@ use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
|
use Symfony\Component\HttpFoundation\JsonResponse;
|
|
use Symfony\Component\HttpFoundation\JsonResponse;
|
|
use Symfony\Component\HttpFoundation\Request;
|
|
use Symfony\Component\HttpFoundation\Request;
|
|
use Symfony\Component\Routing\Attribute\Route;
|
|
use Symfony\Component\Routing\Attribute\Route;
|
|
-use Symfony\Component\Serializer\SerializerInterface;
|
|
|
|
|
|
+use Symfony\Component\Workflow\WorkflowInterface;
|
|
|
|
|
|
class CounterController extends AbstractController
|
|
class CounterController extends AbstractController
|
|
{
|
|
{
|
|
public function __construct(
|
|
public function __construct(
|
|
protected CounterManager $counterManager,
|
|
protected CounterManager $counterManager,
|
|
|
|
+ protected WorkflowInterface $countdownStateMachine,
|
|
|
|
+ protected CounterRepository $counterRepository
|
|
)
|
|
)
|
|
{
|
|
{
|
|
|
|
|
|
@@ -23,7 +25,6 @@ class CounterController extends AbstractController
|
|
#[Route('/counter', name: 'app_counter', methods: ['GET'])]
|
|
#[Route('/counter', name: 'app_counter', methods: ['GET'])]
|
|
public function index(CounterRepository $counterRepository): JsonResponse
|
|
public function index(CounterRepository $counterRepository): JsonResponse
|
|
{
|
|
{
|
|
- //$counter = $this->counterManager->init("P5M", "Youpi");
|
|
|
|
$counters = $counterRepository->findAll();
|
|
$counters = $counterRepository->findAll();
|
|
return $this->json($counters, 200);
|
|
return $this->json($counters, 200);
|
|
}
|
|
}
|
|
@@ -45,7 +46,21 @@ class CounterController extends AbstractController
|
|
#[Route('/counter/start/{id}', name: 'app_counter_start')]
|
|
#[Route('/counter/start/{id}', name: 'app_counter_start')]
|
|
public function startCounter(Counter $counter): JsonResponse
|
|
public function startCounter(Counter $counter): JsonResponse
|
|
{
|
|
{
|
|
- $counter = $this->counterManager->start($counter);
|
|
|
|
|
|
+ $this->countdownStateMachine->apply($counter, Counter::TRANSITION_TO_STARTED);
|
|
|
|
+
|
|
|
|
+ return $this->json($counter, 200);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ #[Route('counter/{id}', name: 'app_counter_id', methods: ['GET'])]
|
|
|
|
+ public function getCounter(Counter $counter): JsonResponse
|
|
|
|
+ {
|
|
|
|
+ return $this->json($counter, 200);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ #[Route('counter/clear/{id}', name: 'app_counter_clear')]
|
|
|
|
+ public function clear(Counter $counter): JsonResponse
|
|
|
|
+ {
|
|
|
|
+ $this->countdownStateMachine->apply($counter, Counter::TRANSITION_TO_READY);
|
|
|
|
|
|
return $this->json($counter, 200);
|
|
return $this->json($counter, 200);
|
|
}
|
|
}
|