Skip to content

Commit

Permalink
Merge pull request #481 from ckrack/feat/redirect-to-created-after-add
Browse files Browse the repository at this point in the history
feat: redirect to created page after adding hydrometer
  • Loading branch information
ckrack authored Feb 27, 2024
2 parents c7ac888 + c72757b commit 160a20d
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 5 deletions.
5 changes: 2 additions & 3 deletions src/Controller/AddHydrometerController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use App\Command\AddHydrometerCommand;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Messenger\MessageBusInterface;
use Symfony\Component\Routing\Attribute\Route;
Expand All @@ -23,8 +24,6 @@ public function __invoke(): Response
$addHydrometerCommand = new AddHydrometerCommand($hydrometerId);
$this->messageBus->dispatch($addHydrometerCommand);

return $this->render('hydrometer/new_hydrometer.html.twig', [
'hydrometer_id' => $hydrometerId,
]);
return new RedirectResponse($this->generateUrl('app_created_hydrometer', ['token' => $hydrometerId->__toString()]));
}
}
19 changes: 19 additions & 0 deletions src/Controller/CreatedHydrometerController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

namespace App\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Attribute\Route;
use Symfony\Component\Uid\Ulid;

class CreatedHydrometerController extends AbstractController
{
#[Route('/created/{token}', name: 'app_created_hydrometer')]
public function __invoke(Ulid $token): Response
{
return $this->render('hydrometer/new_hydrometer.html.twig', [
'hydrometer_id' => $token,
]);
}
}
5 changes: 3 additions & 2 deletions tests/BrewingFlowFunctionalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,9 @@ protected function getService(string $id): mixed

public function testCanAddHydrometer(): Hydrometer
{
$crawler = self::$client->request('POST', '/new');

self::$client->request('POST', '/new');
$this->assertResponseRedirects();
$crawler = self::$client->followRedirect();
$this->assertResponseIsSuccessful();
$this->assertSelectorTextContains('h1', 'New hydrometer added ✅');
$this->assertSelectorTextContains('.example-wrapper', 'Your hydrometer token is: ');
Expand Down

0 comments on commit 160a20d

Please sign in to comment.