diff --git a/app/src/Controller/Group/GroupCreateAction.php b/app/src/Controller/Group/GroupCreateAction.php
index 10ddfcd..716adcb 100644
--- a/app/src/Controller/Group/GroupCreateAction.php
+++ b/app/src/Controller/Group/GroupCreateAction.php
@@ -15,11 +15,11 @@
use Illuminate\Database\Connection;
use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as Request;
-use UserFrosting\Alert\AlertStream;
use UserFrosting\Fortress\RequestSchema;
use UserFrosting\Fortress\RequestSchema\RequestSchemaInterface;
use UserFrosting\Fortress\Transformer\RequestDataTransformer;
use UserFrosting\Fortress\Validator\ServerSideValidator;
+use UserFrosting\I18n\Translator;
use UserFrosting\Sprinkle\Account\Authenticate\Authenticator;
use UserFrosting\Sprinkle\Account\Database\Models\Interfaces\GroupInterface;
use UserFrosting\Sprinkle\Account\Database\Models\Interfaces\UserInterface;
@@ -51,7 +51,7 @@ class GroupCreateAction
* Inject dependencies.
*/
public function __construct(
- protected AlertStream $alert,
+ protected Translator $translator,
protected Authenticator $authenticator,
protected Connection $db,
protected GroupInterface $groupModel,
@@ -71,8 +71,11 @@ public function __construct(
public function __invoke(Request $request, Response $response): Response
{
$this->validateAccess();
- $this->handle($request);
- $payload = json_encode([], JSON_THROW_ON_ERROR);
+ $group = $this->handle($request);
+ $payload = json_encode([
+ 'success' => true,
+ 'message' => $this->translator->translate('GROUP.CREATION_SUCCESSFUL', $group->toArray()),
+ ], JSON_THROW_ON_ERROR);
$response->getBody()->write($payload);
return $response->withHeader('Content-Type', 'application/json');
@@ -82,8 +85,10 @@ public function __invoke(Request $request, Response $response): Response
* Handle the request.
*
* @param Request $request
+ *
+ * @return GroupInterface
*/
- protected function handle(Request $request): void
+ protected function handle(Request $request): GroupInterface
{
// Get POST parameters.
$params = (array) $request->getParsedBody();
@@ -105,7 +110,7 @@ protected function handle(Request $request): void
// All checks passed! log events/activities and create group
// Begin transaction - DB will be rolled back if an exception occurs
- $this->db->transaction(function () use ($data, $currentUser) {
+ $group = $this->db->transaction(function () use ($data, $currentUser) {
// Create the group
$group = new $this->groupModel($data);
$group->save();
@@ -116,8 +121,10 @@ protected function handle(Request $request): void
'user_id' => $currentUser->id,
]);
- $this->alert->addMessage('success', 'GROUP.CREATION_SUCCESSFUL', $data);
+ return $group;
});
+
+ return $group;
}
/**
diff --git a/app/tests/Controller/Group/GroupCreateActionTest.php b/app/tests/Controller/Group/GroupCreateActionTest.php
index bd78fa5..8fbaf90 100644
--- a/app/tests/Controller/Group/GroupCreateActionTest.php
+++ b/app/tests/Controller/Group/GroupCreateActionTest.php
@@ -13,7 +13,6 @@
namespace UserFrosting\Sprinkle\Admin\Tests\Controller\Group;
use Mockery\Adapter\Phpunit\MockeryPHPUnitIntegration;
-use UserFrosting\Alert\AlertStream;
use UserFrosting\Sprinkle\Account\Database\Models\Group;
use UserFrosting\Sprinkle\Account\Database\Models\User;
use UserFrosting\Sprinkle\Account\Testing\WithTestUser;
@@ -81,7 +80,10 @@ public function testPost(): void
// Assert response status & body
$this->assertResponseStatus(200, $response);
- $this->assertJsonResponse([], $response);
+ $this->assertJsonResponse([
+ 'success' => true,
+ 'message' => 'Successfully created group The Foo',
+ ], $response);
// Make sure the user is added to the db by querying it
/** @var Group */
@@ -89,12 +91,6 @@ public function testPost(): void
$this->assertSame('The Foo', $group['name']);
$this->assertSame('fas fas-icon', $group['icon']);
$this->assertSame('Foo description', $group['description']);
-
- // Test message
- /** @var AlertStream */
- $ms = $this->ci->get(AlertStream::class);
- $messages = $ms->getAndClearMessages();
- $this->assertSame('success', array_reverse($messages)[0]['type']);
}
/**
@@ -125,12 +121,6 @@ public function testPostForFailedValidation(): void
'description' => 'Please specify a value for Slug. Slug must be between 1 and 255 characters in length.',
'status' => 400,
], $response);
-
- // Test message
- /** @var AlertStream */
- $ms = $this->ci->get(AlertStream::class);
- $messages = $ms->getAndClearMessages();
- $this->assertSame('danger', array_reverse($messages)[0]['type']);
}
/**