Skip to content

Commit 160a20d

Browse files
authored
Merge pull request #481 from ckrack/feat/redirect-to-created-after-add
feat: redirect to created page after adding hydrometer
2 parents c7ac888 + c72757b commit 160a20d

File tree

3 files changed

+24
-5
lines changed

3 files changed

+24
-5
lines changed

src/Controller/AddHydrometerController.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use App\Command\AddHydrometerCommand;
66
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
7+
use Symfony\Component\HttpFoundation\RedirectResponse;
78
use Symfony\Component\HttpFoundation\Response;
89
use Symfony\Component\Messenger\MessageBusInterface;
910
use Symfony\Component\Routing\Attribute\Route;
@@ -23,8 +24,6 @@ public function __invoke(): Response
2324
$addHydrometerCommand = new AddHydrometerCommand($hydrometerId);
2425
$this->messageBus->dispatch($addHydrometerCommand);
2526

26-
return $this->render('hydrometer/new_hydrometer.html.twig', [
27-
'hydrometer_id' => $hydrometerId,
28-
]);
27+
return new RedirectResponse($this->generateUrl('app_created_hydrometer', ['token' => $hydrometerId->__toString()]));
2928
}
3029
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
namespace App\Controller;
4+
5+
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
6+
use Symfony\Component\HttpFoundation\Response;
7+
use Symfony\Component\Routing\Attribute\Route;
8+
use Symfony\Component\Uid\Ulid;
9+
10+
class CreatedHydrometerController extends AbstractController
11+
{
12+
#[Route('/created/{token}', name: 'app_created_hydrometer')]
13+
public function __invoke(Ulid $token): Response
14+
{
15+
return $this->render('hydrometer/new_hydrometer.html.twig', [
16+
'hydrometer_id' => $token,
17+
]);
18+
}
19+
}

tests/BrewingFlowFunctionalTest.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,9 @@ protected function getService(string $id): mixed
3636

3737
public function testCanAddHydrometer(): Hydrometer
3838
{
39-
$crawler = self::$client->request('POST', '/new');
40-
39+
self::$client->request('POST', '/new');
40+
$this->assertResponseRedirects();
41+
$crawler = self::$client->followRedirect();
4142
$this->assertResponseIsSuccessful();
4243
$this->assertSelectorTextContains('h1', 'New hydrometer added ✅');
4344
$this->assertSelectorTextContains('.example-wrapper', 'Your hydrometer token is: ');

0 commit comments

Comments
 (0)