-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
912bcb3
commit 21a1174
Showing
20 changed files
with
658 additions
and
4 deletions.
There are no files selected for viewing
2 changes: 0 additions & 2 deletions
2
application/backend-monorepo-multiservice/code/run_in_local_test.sh
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 |
---|---|---|
@@ -1,6 +1,4 @@ | ||
#!/bin/bash | ||
set -e | ||
|
||
php bin/console galeas:dbs:updates | ||
|
||
sleep 50000000 |
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
14 changes: 14 additions & 0 deletions
14
.../BoundedContext/Identity/User/Projection/MongoMapping/UserDetails.UserDetails.mongodb.xml
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,14 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<doctrine-mongo-mapping xmlns="http://doctrine-project.org/schemas/odm/doctrine-mongo-mapping" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://doctrine-project.org/schemas/odm/doctrine-mongo-mapping http://doctrine-project.org/schemas/odm/doctrine-mongo-mapping.xsd"> | ||
<document name="Galeas\Api\BoundedContext\Identity\User\Projection\UserDetails\UserDetails" collection="Identity_User_UserDetails_UserDetails"> | ||
<id type="string" strategy="NONE"/> | ||
<embed-one field="primaryEmailStatus"> | ||
<discriminator-field name="type"/> | ||
<discriminator-map> | ||
<discriminator-mapping value="unverifiedEmail" class="Galeas\Api\BoundedContext\Identity\User\Projection\UserDetails\ValueObject\UnverifiedEmail"/> | ||
<discriminator-mapping value="verifiedEmail" class="Galeas\Api\BoundedContext\Identity\User\Projection\UserDetails\ValueObject\VerifiedEmail"/> | ||
<discriminator-mapping value="verifiedButRequestedNewEmail" class="Galeas\Api\BoundedContext\Identity\User\Projection\UserDetails\ValueObject\VerifiedEmailButRequestedNewEmail"/> | ||
</discriminator-map> | ||
</embed-one> | ||
</document> | ||
</doctrine-mongo-mapping> |
6 changes: 6 additions & 0 deletions
6
...Identity/User/Projection/MongoMapping/UserDetails.ValueObject.UnverifiedEmail.mongodb.xml
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,6 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<doctrine-mongo-mapping xmlns="http://doctrine-project.org/schemas/odm/doctrine-mongo-mapping" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://doctrine-project.org/schemas/odm/doctrine-mongo-mapping http://doctrine-project.org/schemas/odm/doctrine-mongo-mapping.xsd"> | ||
<embedded-document name="Galeas\Api\BoundedContext\Identity\User\Projection\UserDetails\ValueObject\UnverifiedEmail"> | ||
<field name="email" type="string"/> | ||
</embedded-document> | ||
</doctrine-mongo-mapping> |
6 changes: 6 additions & 0 deletions
6
...t/Identity/User/Projection/MongoMapping/UserDetails.ValueObject.VerifiedEmail.mongodb.xml
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,6 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<doctrine-mongo-mapping xmlns="http://doctrine-project.org/schemas/odm/doctrine-mongo-mapping" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://doctrine-project.org/schemas/odm/doctrine-mongo-mapping http://doctrine-project.org/schemas/odm/doctrine-mongo-mapping.xsd"> | ||
<embedded-document name="Galeas\Api\BoundedContext\Identity\User\Projection\UserDetails\ValueObject\VerifiedEmail"> | ||
<field name="email" type="string"/> | ||
</embedded-document> | ||
</doctrine-mongo-mapping> |
7 changes: 7 additions & 0 deletions
7
...ection/MongoMapping/UserDetails.ValueObject.VerifiedEmailButRequestedNewEmail.mongodb.xml
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,7 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<doctrine-mongo-mapping xmlns="http://doctrine-project.org/schemas/odm/doctrine-mongo-mapping" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://doctrine-project.org/schemas/odm/doctrine-mongo-mapping http://doctrine-project.org/schemas/odm/doctrine-mongo-mapping.xsd"> | ||
<embedded-document name="Galeas\Api\BoundedContext\Identity\User\Projection\UserDetails\ValueObject\VerifiedEmailButRequestedNewEmail"> | ||
<field name="verifiedEmail" type="string"/> | ||
<field name="requestedEmail" type="string"/> | ||
</embedded-document> | ||
</doctrine-mongo-mapping> |
81 changes: 81 additions & 0 deletions
81
...tiservice/code/src/BoundedContext/Identity/User/Projection/UserDetails/GetUserDetails.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,81 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Galeas\Api\BoundedContext\Identity\User\Projection\UserDetails; | ||
|
||
use Doctrine\ODM\MongoDB\DocumentManager; | ||
use Galeas\Api\BoundedContext\Identity\User\Projection\UserDetails\ValueObject\UnverifiedEmail; | ||
use Galeas\Api\BoundedContext\Identity\User\Projection\UserDetails\ValueObject\VerifiedEmail; | ||
use Galeas\Api\BoundedContext\Identity\User\Projection\UserDetails\ValueObject\VerifiedEmailButRequestedNewEmail; | ||
use Galeas\Api\CommonException\ProjectionCannotRead; | ||
|
||
class GetUserDetails | ||
{ | ||
private DocumentManager $projectionDocumentManager; | ||
|
||
public function __construct(DocumentManager $projectionDocumentManager) | ||
{ | ||
$this->projectionDocumentManager = $projectionDocumentManager; | ||
} | ||
|
||
/** | ||
* @return array{userId: string, primaryEmailStatus: array{unverifiedEmail: array{email: string}}|array{verifiedEmail: array{email: string}}|array{verifiedEmailButRequestedNewEmail: array{requestedEmail: string, verifiedEmail: string}}} | ||
* | ||
* @throws ProjectionCannotRead | ||
*/ | ||
public function getUserDetails(string $userId): array | ||
{ | ||
try { | ||
$userDetails = $this->projectionDocumentManager | ||
->createQueryBuilder(UserDetails::class) | ||
->field('id')->equals($userId) | ||
->getQuery() | ||
->getSingleResult() | ||
; | ||
|
||
if ($userDetails instanceof UserDetails) { | ||
$status = $userDetails->getPrimaryEmailStatus(); | ||
|
||
switch ($status) { | ||
case $status instanceof UnverifiedEmail: | ||
$primaryEmailStatus = [ | ||
'unverifiedEmail' => [ | ||
'email' => $status->getEmail(), | ||
], | ||
]; | ||
|
||
break; | ||
|
||
case $status instanceof VerifiedEmail: | ||
$primaryEmailStatus = [ | ||
'verifiedEmail' => [ | ||
'email' => $status->getEmail(), | ||
], | ||
]; | ||
|
||
break; | ||
|
||
case $status instanceof VerifiedEmailButRequestedNewEmail: | ||
$primaryEmailStatus = [ | ||
'verifiedButRequestedNewEmail' => [ | ||
'requestedEmail' => $status->getRequestedEmail(), | ||
'verifiedEmail' => $status->getVerifiedEmail(), | ||
], | ||
]; | ||
|
||
break; | ||
} | ||
|
||
return [ | ||
'userId' => $userDetails->getUserId(), | ||
'primaryEmailStatus' => $primaryEmailStatus, | ||
]; | ||
} | ||
|
||
throw new \Exception('Expected UserDetails instance, got nothing.'); | ||
} catch (\Throwable $exception) { | ||
throw new ProjectionCannotRead($exception); | ||
} | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
...multiservice/code/src/BoundedContext/Identity/User/Projection/UserDetails/UserDetails.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,44 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Galeas\Api\BoundedContext\Identity\User\Projection\UserDetails; | ||
|
||
use Galeas\Api\BoundedContext\Identity\User\Projection\UserDetails\ValueObject\UnverifiedEmail; | ||
use Galeas\Api\BoundedContext\Identity\User\Projection\UserDetails\ValueObject\VerifiedEmail; | ||
use Galeas\Api\BoundedContext\Identity\User\Projection\UserDetails\ValueObject\VerifiedEmailButRequestedNewEmail; | ||
|
||
class UserDetails | ||
{ | ||
private string $id; | ||
|
||
private UnverifiedEmail|VerifiedEmail|VerifiedEmailButRequestedNewEmail $primaryEmailStatus; | ||
|
||
private function __construct() {} | ||
|
||
public function getUserId(): string | ||
{ | ||
return $this->id; | ||
} | ||
|
||
public function getPrimaryEmailStatus(): UnverifiedEmail|VerifiedEmail|VerifiedEmailButRequestedNewEmail | ||
{ | ||
return $this->primaryEmailStatus; | ||
} | ||
|
||
public function changePrimaryEmailStatus(UnverifiedEmail|VerifiedEmail|VerifiedEmailButRequestedNewEmail $primaryEmailStatus): self | ||
{ | ||
$this->primaryEmailStatus = $primaryEmailStatus; | ||
|
||
return $this; | ||
} | ||
|
||
public static function fromProperties(string $userId, UnverifiedEmail|VerifiedEmail|VerifiedEmailButRequestedNewEmail $primaryEmailStatus): self | ||
{ | ||
$userDetails = new self(); | ||
$userDetails->id = $userId; | ||
$userDetails->primaryEmailStatus = $primaryEmailStatus; | ||
|
||
return $userDetails; | ||
} | ||
} |
88 changes: 88 additions & 0 deletions
88
...ice/code/src/BoundedContext/Identity/User/Projection/UserDetails/UserDetailsProjector.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,88 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Galeas\Api\BoundedContext\Identity\User\Projection\UserDetails; | ||
|
||
use Doctrine\ODM\MongoDB\DocumentManager; | ||
use Galeas\Api\BoundedContext\Identity\User\Event\PrimaryEmailChangeRequested; | ||
use Galeas\Api\BoundedContext\Identity\User\Event\PrimaryEmailVerified; | ||
use Galeas\Api\BoundedContext\Identity\User\Event\SignedUp; | ||
use Galeas\Api\BoundedContext\Identity\User\Projection\UserDetails\ValueObject\UnverifiedEmail; | ||
use Galeas\Api\BoundedContext\Identity\User\Projection\UserDetails\ValueObject\VerifiedEmail; | ||
use Galeas\Api\BoundedContext\Identity\User\Projection\UserDetails\ValueObject\VerifiedEmailButRequestedNewEmail; | ||
use Galeas\Api\Common\Event\Event; | ||
use Galeas\Api\CommonException\ProjectionCannotProcess; | ||
use Galeas\Api\Service\QueueProcessor\EventProjector; | ||
|
||
class UserDetailsProjector implements EventProjector | ||
{ | ||
private DocumentManager $projectionDocumentManager; | ||
|
||
public function __construct(DocumentManager $projectionDocumentManager) | ||
{ | ||
$this->projectionDocumentManager = $projectionDocumentManager; | ||
} | ||
|
||
public function project(Event $event): void | ||
{ | ||
try { | ||
if ( | ||
$event instanceof SignedUp | ||
|| $event instanceof PrimaryEmailVerified | ||
|| $event instanceof PrimaryEmailChangeRequested | ||
) { | ||
$userId = $event->aggregateId()->id(); | ||
} else { | ||
return; | ||
} | ||
|
||
$userDetails = $this->projectionDocumentManager | ||
->createQueryBuilder(UserDetails::class) | ||
->field('id')->equals($userId) | ||
->getQuery() | ||
->getSingleResult() | ||
; | ||
|
||
if ($userDetails instanceof UserDetails && $event instanceof SignedUp) { | ||
$userDetails = UserDetails::fromProperties($userId, UnverifiedEmail::fromProperties( | ||
$event->primaryEmail() | ||
)); | ||
} elseif ($userDetails instanceof UserDetails) { | ||
$currentStatus = $userDetails->getPrimaryEmailStatus(); | ||
$newStatus = $this->getPrimaryEmailStatusFromEvent($event, $currentStatus); | ||
$userDetails->changePrimaryEmailStatus($newStatus); | ||
} else { | ||
throw new \InvalidArgumentException('Unsupported operation'); | ||
} | ||
|
||
$this->projectionDocumentManager->persist($userDetails); | ||
$this->projectionDocumentManager->flush(); | ||
} catch (\Throwable $throwable) { | ||
throw new ProjectionCannotProcess($throwable); | ||
} | ||
} | ||
|
||
/** | ||
* @throws \InvalidArgumentException | ||
*/ | ||
private function getPrimaryEmailStatusFromEvent( | ||
Event $event, | ||
null|UnverifiedEmail|VerifiedEmail|VerifiedEmailButRequestedNewEmail $currentStatus = null | ||
): UnverifiedEmail|VerifiedEmail|VerifiedEmailButRequestedNewEmail { | ||
if ($event instanceof PrimaryEmailVerified && $currentStatus instanceof UnverifiedEmail) { | ||
return VerifiedEmail::fromProperties($currentStatus->getEmail()); | ||
} | ||
if ($event instanceof PrimaryEmailVerified && $currentStatus instanceof VerifiedEmailButRequestedNewEmail) { | ||
return VerifiedEmail::fromProperties($currentStatus->getRequestedEmail()); | ||
} | ||
if ($event instanceof PrimaryEmailChangeRequested && $currentStatus instanceof UnverifiedEmail) { | ||
return UnverifiedEmail::fromProperties($event->newEmailRequested()); | ||
} | ||
if ($event instanceof PrimaryEmailChangeRequested && $currentStatus instanceof VerifiedEmailButRequestedNewEmail) { | ||
return VerifiedEmailButRequestedNewEmail::fromProperties($currentStatus->getVerifiedEmail(), $event->newEmailRequested()); | ||
} | ||
|
||
throw new \InvalidArgumentException('Unsupported operation'); | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
...e/src/BoundedContext/Identity/User/Projection/UserDetails/ValueObject/UnverifiedEmail.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,25 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Galeas\Api\BoundedContext\Identity\User\Projection\UserDetails\ValueObject; | ||
|
||
class UnverifiedEmail | ||
{ | ||
private string $email; | ||
|
||
private function __construct() {} | ||
|
||
public function getEmail(): string | ||
{ | ||
return $this->email; | ||
} | ||
|
||
public static function fromProperties(string $email): self | ||
{ | ||
$instance = new self(); | ||
$instance->email = $email; | ||
|
||
return $instance; | ||
} | ||
} |
Oops, something went wrong.