-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Expand user #3
Expand user #3
Changes from 5 commits
148bafc
ff38ada
b58afde
2a2c8f7
5e7bf13
eb41299
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -7,6 +7,24 @@ | |||||
|
||||||
namespace SprykerEco\Zed\AmazonQuicksight\Business; | ||||||
|
||||||
use Generated\Shared\Transfer\UserCollectionTransfer; | ||||||
|
||||||
interface AmazonQuicksightFacadeInterface | ||||||
{ | ||||||
/** | ||||||
* Specification: | ||||||
* - 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 expandUserCollectionWithQuicksightUser( | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
UserCollectionTransfer $userCollectionTransfer | ||||||
): UserCollectionTransfer; | ||||||
} |
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->getUserIds($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 getUserIds(UserCollectionTransfer $userCollectionTransfer): array | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
{ | ||||||
$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; | ||||||
} | ||||||
} |
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; | ||
} |
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 QuicksightUserUserExpanderPlugin extends AbstractPlugin implements UserExpanderPluginInterface | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe we can make an exception from our conventions and name this plugin |
||
{ | ||
/** | ||
* {@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()->expandUserCollectionWithQuicksightUser($userCollectionTransfer); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?php | ||
|
||
/** | ||
* MIT License | ||
* Use of this software requires acceptance of the Evaluation License Agreement. See LICENSE file. | ||
*/ | ||
|
||
namespace SprykerEco\Zed\AmazonQuicksight\Persistence\Propel\Mapper; | ||
|
||
use Generated\Shared\Transfer\QuicksightUserTransfer; | ||
use Orm\Zed\AmazonQuicksight\Persistence\SpyQuicksightUser; | ||
use Propel\Runtime\Collection\Collection; | ||
|
||
class QuicksightUserMapper | ||
{ | ||
/** | ||
* @param \Propel\Runtime\Collection\Collection<\Orm\Zed\AmazonQuicksight\Persistence\SpyQuicksightUser> $quicksightUserEntities | ||
* @param list<\Generated\Shared\Transfer\QuicksightUserTransfer> $quicksightUserTransfers | ||
* | ||
* @return list<\Generated\Shared\Transfer\QuicksightUserTransfer> | ||
*/ | ||
public function mapQuicksightUserEntitiesToQuicksightUserTransfers( | ||
Collection $quicksightUserEntities, | ||
array $quicksightUserTransfers | ||
): array { | ||
foreach ($quicksightUserEntities as $quicksightUserEntity) { | ||
$quicksightUserTransfers[] = $this->mapQuicksightUserEntityToQuicksightUserTransfer( | ||
$quicksightUserEntity, | ||
new QuicksightUserTransfer(), | ||
); | ||
} | ||
|
||
return $quicksightUserTransfers; | ||
} | ||
|
||
/** | ||
* @param \Orm\Zed\AmazonQuicksight\Persistence\SpyQuicksightUser $quicksightUserEntity | ||
* @param \Generated\Shared\Transfer\QuicksightUserTransfer $quicksightUserTransfer | ||
* | ||
* @return \Generated\Shared\Transfer\QuicksightUserTransfer | ||
*/ | ||
protected function mapQuicksightUserEntityToQuicksightUserTransfer( | ||
SpyQuicksightUser $quicksightUserEntity, | ||
QuicksightUserTransfer $quicksightUserTransfer | ||
): QuicksightUserTransfer { | ||
return $quicksightUserTransfer->fromArray($quicksightUserEntity->toArray(), true); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
Requires...
part usually goes first in the specification.