-
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.
Merge branch 'feature/cc-34041/dev-quick-sight-mvp' into feature/cc-3…
…4041/cc-34136-persist-qs-user
- Loading branch information
Showing
15 changed files
with
417 additions
and
0 deletions.
There are no files selected for viewing
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
84 changes: 84 additions & 0 deletions
84
src/SprykerEco/Zed/AmazonQuicksight/Business/Expander/UserExpander.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,84 @@ | ||
<?php | ||
|
||
/** | ||
* MIT License | ||
* Use of this software requires acceptance of the Evaluation License Agreement. See LICENSE file. | ||
*/ | ||
|
||
namespace SprykerEco\Zed\AmazonQuicksight\Business\Expander; | ||
|
||
use Generated\Shared\Transfer\UserCollectionTransfer; | ||
use SprykerEco\Zed\AmazonQuicksight\Persistence\AmazonQuicksightRepositoryInterface; | ||
|
||
class UserExpander implements UserExpanderInterface | ||
{ | ||
/** | ||
* @var \SprykerEco\Zed\AmazonQuicksight\Persistence\AmazonQuicksightRepositoryInterface | ||
*/ | ||
protected AmazonQuicksightRepositoryInterface $amazonQuicksightRepository; | ||
|
||
/** | ||
* @param \SprykerEco\Zed\AmazonQuicksight\Persistence\AmazonQuicksightRepositoryInterface $amazonQuicksightRepository | ||
*/ | ||
public function __construct(AmazonQuicksightRepositoryInterface $amazonQuicksightRepository) | ||
{ | ||
$this->amazonQuicksightRepository = $amazonQuicksightRepository; | ||
} | ||
|
||
/** | ||
* @param \Generated\Shared\Transfer\UserCollectionTransfer $userCollectionTransfer | ||
* | ||
* @return \Generated\Shared\Transfer\UserCollectionTransfer | ||
*/ | ||
public function expandUserCollectionWithQuicksightUser( | ||
UserCollectionTransfer $userCollectionTransfer | ||
): UserCollectionTransfer { | ||
$userIds = $this->extractUserIds($userCollectionTransfer); | ||
$quicksightUserTransfers = $this->amazonQuicksightRepository->getQuicksightUsersByUserIds($userIds); | ||
|
||
if (!$quicksightUserTransfers) { | ||
return $userCollectionTransfer; | ||
} | ||
|
||
$quicksightUserTransfersIndexedByIdUser = $this->getQuicksightUserTransfersIndexedByIdUser($quicksightUserTransfers); | ||
|
||
foreach ($userCollectionTransfer->getUsers() as $userTransfer) { | ||
$idUser = $userTransfer->getIdUserOrFail(); | ||
if (isset($quicksightUserTransfersIndexedByIdUser[$idUser])) { | ||
$userTransfer->setQuicksightUser($quicksightUserTransfersIndexedByIdUser[$idUser]); | ||
} | ||
} | ||
|
||
return $userCollectionTransfer; | ||
} | ||
|
||
/** | ||
* @param \Generated\Shared\Transfer\UserCollectionTransfer $userCollectionTransfer | ||
* | ||
* @return list<int> | ||
*/ | ||
protected function extractUserIds(UserCollectionTransfer $userCollectionTransfer): array | ||
{ | ||
$userIds = []; | ||
foreach ($userCollectionTransfer->getUsers() as $userTransfer) { | ||
$userIds[] = $userTransfer->getIdUserOrFail(); | ||
} | ||
|
||
return $userIds; | ||
} | ||
|
||
/** | ||
* @param list<\Generated\Shared\Transfer\QuicksightUserTransfer> $quicksightUserTransfers | ||
* | ||
* @return array<int, \Generated\Shared\Transfer\QuicksightUserTransfer> | ||
*/ | ||
protected function getQuicksightUserTransfersIndexedByIdUser(array $quicksightUserTransfers): array | ||
{ | ||
$quicksightUserTransfersIndexedByIdUser = []; | ||
foreach ($quicksightUserTransfers as $quicksightUserTransfer) { | ||
$quicksightUserTransfersIndexedByIdUser[$quicksightUserTransfer->getFkUserOrFail()] = $quicksightUserTransfer; | ||
} | ||
|
||
return $quicksightUserTransfersIndexedByIdUser; | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
src/SprykerEco/Zed/AmazonQuicksight/Business/Expander/UserExpanderInterface.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,22 @@ | ||
<?php | ||
|
||
/** | ||
* MIT License | ||
* Use of this software requires acceptance of the Evaluation License Agreement. See LICENSE file. | ||
*/ | ||
|
||
namespace SprykerEco\Zed\AmazonQuicksight\Business\Expander; | ||
|
||
use Generated\Shared\Transfer\UserCollectionTransfer; | ||
|
||
interface UserExpanderInterface | ||
{ | ||
/** | ||
* @param \Generated\Shared\Transfer\UserCollectionTransfer $userCollectionTransfer | ||
* | ||
* @return \Generated\Shared\Transfer\UserCollectionTransfer | ||
*/ | ||
public function expandUserCollectionWithQuicksightUser( | ||
UserCollectionTransfer $userCollectionTransfer | ||
): UserCollectionTransfer; | ||
} |
38 changes: 38 additions & 0 deletions
38
...prykerEco/Zed/AmazonQuicksight/Communication/Plugin/User/QuicksightUserExpanderPlugin.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,38 @@ | ||
<?php | ||
|
||
/** | ||
* MIT License | ||
* Use of this software requires acceptance of the Evaluation License Agreement. See LICENSE file. | ||
*/ | ||
|
||
namespace SprykerEco\Zed\AmazonQuicksight\Communication\Plugin\User; | ||
|
||
use Generated\Shared\Transfer\UserCollectionTransfer; | ||
use Spryker\Zed\Kernel\Communication\AbstractPlugin; | ||
use Spryker\Zed\UserExtension\Dependency\Plugin\UserExpanderPluginInterface; | ||
|
||
/** | ||
* @method \SprykerEco\Zed\AmazonQuicksight\AmazonQuicksightConfig getConfig() | ||
* @method \SprykerEco\Zed\AmazonQuicksight\Business\AmazonQuicksightFacadeInterface getFacade() | ||
* @method \SprykerEco\Zed\AmazonQuicksight\Communication\AmazonQuicksightCommunicationFactory getFactory() | ||
*/ | ||
class QuicksightUserExpanderPlugin extends AbstractPlugin implements UserExpanderPluginInterface | ||
{ | ||
/** | ||
* {@inheritDoc} | ||
* - Iterates over `UserCollectionTransfer.users`. | ||
* - Requires `UserTransfer.idUser` for each user in collection to be set. | ||
* - Finds Quicksight users by `UserTransfer.idUser` in DB. | ||
* - Populates `UserTransfer.quicksightUser` in collection with found Quicksight users. | ||
* | ||
* @api | ||
* | ||
* @param \Generated\Shared\Transfer\UserCollectionTransfer $userCollectionTransfer | ||
* | ||
* @return \Generated\Shared\Transfer\UserCollectionTransfer | ||
*/ | ||
public function expand(UserCollectionTransfer $userCollectionTransfer): UserCollectionTransfer | ||
{ | ||
return $this->getFacade()->expandUserCollectionWithQuicksightUsers($userCollectionTransfer); | ||
} | ||
} |
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
Oops, something went wrong.