-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add onboarding completion functionality and related user options.
- Loading branch information
1 parent
54c4401
commit f91a522
Showing
16 changed files
with
362 additions
and
10 deletions.
There are no files selected for viewing
24 changes: 24 additions & 0 deletions
24
src/EconumoBundle/Application/User/Assembler/CompleteOnboardingV1ResultAssembler.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,24 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\EconumoBundle\Application\User\Assembler; | ||
|
||
use App\EconumoBundle\Application\User\Dto\CompleteOnboardingV1ResultDto; | ||
use App\EconumoBundle\Domain\Entity\ValueObject\Id; | ||
|
||
readonly class CompleteOnboardingV1ResultAssembler | ||
{ | ||
public function __construct( | ||
private CurrentUserIdToDtoResultAssembler $currentUserIdToDtoResultAssembler | ||
) { | ||
} | ||
|
||
public function assemble(Id $userId): CompleteOnboardingV1ResultDto | ||
{ | ||
$result = new CompleteOnboardingV1ResultDto(); | ||
$result->user = $this->currentUserIdToDtoResultAssembler->assemble($userId); | ||
|
||
return $result; | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
src/EconumoBundle/Application/User/Dto/CompleteOnboardingV1RequestDto.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,20 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\EconumoBundle\Application\User\Dto; | ||
|
||
use OpenApi\Annotations as OA; | ||
|
||
/** | ||
* @OA\Schema( | ||
* required={"id"} | ||
* ) | ||
*/ | ||
class CompleteOnboardingV1RequestDto | ||
{ | ||
/** | ||
* @OA\Property(example="123") | ||
*/ | ||
public string $id; | ||
} |
17 changes: 17 additions & 0 deletions
17
src/EconumoBundle/Application/User/Dto/CompleteOnboardingV1ResultDto.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,17 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\EconumoBundle\Application\User\Dto; | ||
|
||
use OpenApi\Annotations as OA; | ||
|
||
/** | ||
* @OA\Schema( | ||
* required={"user"} | ||
* ) | ||
*/ | ||
class CompleteOnboardingV1ResultDto | ||
{ | ||
public CurrentUserResultDto $user; | ||
} |
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,28 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\EconumoBundle\Application\User; | ||
|
||
use App\EconumoBundle\Application\User\Dto\CompleteOnboardingV1RequestDto; | ||
use App\EconumoBundle\Application\User\Dto\CompleteOnboardingV1ResultDto; | ||
use App\EconumoBundle\Application\User\Assembler\CompleteOnboardingV1ResultAssembler; | ||
use App\EconumoBundle\Domain\Entity\ValueObject\Id; | ||
use App\EconumoBundle\Domain\Service\UserServiceInterface; | ||
|
||
readonly class OnboardingService | ||
{ | ||
public function __construct( | ||
private CompleteOnboardingV1ResultAssembler $completeOnboardingV1ResultAssembler, | ||
private UserServiceInterface $userService | ||
) { | ||
} | ||
|
||
public function completeOnboarding( | ||
CompleteOnboardingV1RequestDto $dto, | ||
Id $userId | ||
): CompleteOnboardingV1ResultDto { | ||
$this->userService->completeOnboarding($userId); | ||
return $this->completeOnboardingV1ResultAssembler->assemble($userId); | ||
} | ||
} |
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
43 changes: 43 additions & 0 deletions
43
src/EconumoBundle/Infrastructure/Doctrine/Migration/Version20241222201140.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,43 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\EconumoBundle\Infrastructure\Doctrine\Migration; | ||
|
||
use Doctrine\DBAL\Schema\Schema; | ||
use Doctrine\Migrations\AbstractMigration; | ||
use Ramsey\Uuid\Uuid; | ||
|
||
/** | ||
* Auto-generated Migration: Please modify to your needs! | ||
*/ | ||
final class Version20241222201140 extends AbstractMigration | ||
{ | ||
public function getDescription() : string | ||
{ | ||
return ''; | ||
} | ||
|
||
public function up(Schema $schema) : void | ||
{ | ||
// this up() migration is auto-generated, please modify it to your needs | ||
$this->skipIf($this->connection->getDatabasePlatform()->getName() !== 'sqlite', "Migration can only be executed safely on 'sqlite'."); | ||
|
||
$users = $this->connection->fetchAllAssociative('SELECT id, created_at, updated_at FROM users;'); | ||
foreach ($users as $i => $user) { | ||
$id = (string) Uuid::uuid4(); | ||
$userId = $user['id']; | ||
$createdAt = $user['created_at']; | ||
$updatedAt = $user['updated_at']; | ||
$this->addSql(sprintf('INSERT INTO users_options (id, user_id, name, value, created_at, updated_at) VALUES (\'%s\', \'%s\', \'onboarding\', \'started\', \'%s\', \'%s\')', $id, $userId, $createdAt, $updatedAt)); | ||
} | ||
} | ||
|
||
public function down(Schema $schema) : void | ||
{ | ||
// this down() migration is auto-generated, please modify it to your needs | ||
$this->skipIf($this->connection->getDatabasePlatform()->getName() !== 'sqlite', "Migration can only be executed safely on 'sqlite'."); | ||
|
||
$this->addSql("DELETE FROM users_options WHERE name = 'onboarding';"); | ||
} | ||
} |
69 changes: 69 additions & 0 deletions
69
src/EconumoBundle/UI/Controller/Api/User/Onboarding/CompleteOnboardingV1Controller.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,69 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\EconumoBundle\UI\Controller\Api\User\Onboarding; | ||
|
||
use App\EconumoBundle\Application\User\OnboardingService; | ||
use App\EconumoBundle\Application\User\Dto\CompleteOnboardingV1RequestDto; | ||
use App\EconumoBundle\UI\Controller\Api\User\Onboarding\Validation\CompleteOnboardingV1Form; | ||
use App\EconumoBundle\Application\Exception\ValidationException; | ||
use App\EconumoBundle\Domain\Entity\User; | ||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; | ||
use Symfony\Component\HttpFoundation\Request; | ||
use Symfony\Component\HttpFoundation\Response; | ||
use App\EconumoBundle\UI\Service\Validator\ValidatorInterface; | ||
use App\EconumoBundle\UI\Service\Response\ResponseFactory; | ||
use Symfony\Component\Routing\Annotation\Route; | ||
use Nelmio\ApiDocBundle\Annotation\Model; | ||
use OpenApi\Annotations as OA; | ||
|
||
class CompleteOnboardingV1Controller extends AbstractController | ||
{ | ||
public function __construct( | ||
private readonly OnboardingService $onboardingService, | ||
private readonly ValidatorInterface $validator | ||
) { | ||
} | ||
|
||
/** | ||
* Complete users onboarding | ||
* | ||
* @OA\Tag(name="User"), | ||
* @OA\RequestBody(@OA\JsonContent(ref=@Model(type=\App\EconumoBundle\Application\User\Dto\CompleteOnboardingV1RequestDto::class))), | ||
* @OA\Response( | ||
* response=200, | ||
* description="OK", | ||
* @OA\JsonContent( | ||
* type="object", | ||
* allOf={ | ||
* @OA\Schema(ref="#/components/schemas/JsonResponseOk"), | ||
* @OA\Schema( | ||
* @OA\Property( | ||
* property="data", | ||
* ref=@Model(type=\App\EconumoBundle\Application\User\Dto\CompleteOnboardingV1ResultDto::class) | ||
* ) | ||
* ) | ||
* } | ||
* ) | ||
* ), | ||
* @OA\Response(response=400, description="Bad Request", @OA\JsonContent(ref="#/components/schemas/JsonResponseError")), | ||
* @OA\Response(response=401, description="Unauthorized", @OA\JsonContent(ref="#/components/schemas/JsonResponseUnauthorized")), | ||
* @OA\Response(response=500, description="Internal Server Error", @OA\JsonContent(ref="#/components/schemas/JsonResponseException")), | ||
* | ||
* | ||
* @return Response | ||
* @throws ValidationException | ||
*/ | ||
#[Route(path: '/api/v1/user/complete-onboarding', name: 'api_user_complete_onboarding', methods: ['POST'])] | ||
public function __invoke(Request $request): Response | ||
{ | ||
$dto = new CompleteOnboardingV1RequestDto(); | ||
$this->validator->validate(CompleteOnboardingV1Form::class, $request->request->all(), $dto); | ||
/** @var User $user */ | ||
$user = $this->getUser(); | ||
$result = $this->onboardingService->completeOnboarding($dto, $user->getId()); | ||
|
||
return ResponseFactory::createOkResponse($request, $result); | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
src/EconumoBundle/UI/Controller/Api/User/Onboarding/Validation/CompleteOnboardingV1Form.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,21 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\EconumoBundle\UI\Controller\Api\User\Onboarding\Validation; | ||
|
||
use Symfony\Component\Form\AbstractType; | ||
use Symfony\Component\Form\FormBuilderInterface; | ||
use Symfony\Component\OptionsResolver\OptionsResolver; | ||
|
||
class CompleteOnboardingV1Form extends AbstractType | ||
{ | ||
public function configureOptions(OptionsResolver $resolver): void | ||
{ | ||
$resolver->setDefaults(['csrf_protection' => false]); | ||
} | ||
|
||
public function buildForm(FormBuilderInterface $builder, array $options): void | ||
{ | ||
} | ||
} |
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 |
---|---|---|
|
@@ -6,7 +6,7 @@ | |
'name' => 'John', | ||
'identifier' => 'ce2ff29bb72be7ee509d088bce780c32', | ||
'email' => '[email protected]', | ||
'avatar_url' => '', | ||
'avatar_url' => 'https://i.pravatar.cc/100?img=60', | ||
'password' => 'OWSXlB4C5oBuH6U/NTNZd0T2jQiTJXZvOQzaDgPc6i7IMyeeY+URRaNAlZdQ4DF8UVyRSkW1+n0IC9xog1HPrg==', | ||
'salt' => '9dfc7b4f71b29d37e8b3855cac8314082ff8afc6', | ||
'created_at' => date('Y-m-01 10:00:00'), | ||
|
@@ -17,7 +17,7 @@ | |
'name' => 'Dany', | ||
'identifier' => 'e1e3c80be7c8183143a09b7078bfc8e0', | ||
'email' => '[email protected]', | ||
'avatar_url' => '', | ||
'avatar_url' => 'https://i.pravatar.cc/100?img=47', | ||
'password' => 'Ac6pLj+WdJYTTK58AKKSp1uHVtdtFVSjZVOLxt6oFAzqKIZ7nKBD7cztXt5vJn7q2U2iMTCRapP/VWf+nvtSoA==', | ||
'salt' => '6ab0b56832e1f148e1051499d341ca772fb3b322', | ||
'created_at' => date('Y-m-01 10:00:00'), | ||
|
@@ -28,7 +28,7 @@ | |
'name' => 'Sansa', | ||
'identifier' => 'efb5dee2edea2a03a803c9c77b7dae94', | ||
'email' => '[email protected]', | ||
'avatar_url' => '', | ||
'avatar_url' => 'https://i.pravatar.cc/100?img=20', | ||
'password' => 'Ac6pLj+WdJYTTK58AKKSp1uHVtdtFVSjZVOLxt6oFAzqKIZ7nKBD7cztXt5vJn7q2U2iMTCRapP/VWf+nvtSoA==', | ||
'salt' => '6ab0b56832e1f148e1051499d341ca772fb3b322', | ||
'created_at' => date('Y-m-01 10:00:00'), | ||
|
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
Oops, something went wrong.