-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15965 from atomiix/notification-CQRS
Implements CQRS on Notifications
- Loading branch information
Showing
13 changed files
with
888 additions
and
4 deletions.
There are no files selected for viewing
47 changes: 47 additions & 0 deletions
47
src/Adapter/Notification/CommandHandler/UpdateEmployeeNotificationLastElementHandler.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,47 @@ | ||
<?php | ||
/** | ||
* 2007-2019 PrestaShop SA and Contributors | ||
* | ||
* NOTICE OF LICENSE | ||
* | ||
* This source file is subject to the Open Software License (OSL 3.0) | ||
* that is bundled with this package in the file LICENSE.txt. | ||
* It is also available through the world-wide-web at this URL: | ||
* https://opensource.org/licenses/OSL-3.0 | ||
* If you did not receive a copy of the license and are unable to | ||
* obtain it through the world-wide-web, please send an email | ||
* to license@prestashop.com so we can send you a copy immediately. | ||
* | ||
* DISCLAIMER | ||
* | ||
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer | ||
* versions in the future. If you wish to customize PrestaShop for your | ||
* needs please refer to https://www.prestashop.com for more information. | ||
* | ||
* @author PrestaShop SA <contact@prestashop.com> | ||
* @copyright 2007-2019 PrestaShop SA and Contributors | ||
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) | ||
* International Registered Trademark & Property of PrestaShop SA | ||
*/ | ||
|
||
namespace PrestaShop\PrestaShop\Adapter\Notification\CommandHandler; | ||
|
||
use Notification; | ||
use PrestaShop\PrestaShop\Core\Domain\Notification\Command\UpdateEmployeeNotificationLastElementCommand; | ||
use PrestaShop\PrestaShop\Core\Domain\Notification\CommandHandler\UpdateEmployeeNotificationLastElementCommandHandlerInterface; | ||
|
||
/** | ||
* Handle update employee's last notification element of a given type | ||
* | ||
* @internal | ||
*/ | ||
final class UpdateEmployeeNotificationLastElementHandler implements UpdateEmployeeNotificationLastElementCommandHandlerInterface | ||
{ | ||
/** | ||
* @param UpdateEmployeeNotificationLastElementCommand $command | ||
*/ | ||
public function handle(UpdateEmployeeNotificationLastElementCommand $command) | ||
{ | ||
(new Notification())->updateEmployeeLastElement($command->getType()); | ||
} | ||
} |
77 changes: 77 additions & 0 deletions
77
src/Adapter/Notification/QueryHandler/GetNotificationLastElementsHandler.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,77 @@ | ||
<?php | ||
/** | ||
* 2007-2019 PrestaShop SA and Contributors | ||
* | ||
* NOTICE OF LICENSE | ||
* | ||
* This source file is subject to the Open Software License (OSL 3.0) | ||
* that is bundled with this package in the file LICENSE.txt. | ||
* It is also available through the world-wide-web at this URL: | ||
* https://opensource.org/licenses/OSL-3.0 | ||
* If you did not receive a copy of the license and are unable to | ||
* obtain it through the world-wide-web, please send an email | ||
* to license@prestashop.com so we can send you a copy immediately. | ||
* | ||
* DISCLAIMER | ||
* | ||
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer | ||
* versions in the future. If you wish to customize PrestaShop for your | ||
* needs please refer to https://www.prestashop.com for more information. | ||
* | ||
* @author PrestaShop SA <contact@prestashop.com> | ||
* @copyright 2007-2019 PrestaShop SA and Contributors | ||
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) | ||
* International Registered Trademark & Property of PrestaShop SA | ||
*/ | ||
|
||
namespace PrestaShop\PrestaShop\Adapter\Notification\QueryHandler; | ||
|
||
use Notification; | ||
use PrestaShop\PrestaShop\Core\Domain\Notification\Query\GetNotificationLastElements; | ||
use PrestaShop\PrestaShop\Core\Domain\Notification\QueryHandler\GetNotificationLastElementsHandlerInterface; | ||
use PrestaShop\PrestaShop\Core\Domain\Notification\QueryResult\NotificationResult; | ||
use PrestaShop\PrestaShop\Core\Domain\Notification\QueryResult\NotificationsResult; | ||
use PrestaShop\PrestaShop\Core\Domain\Notification\QueryResult\NotificationsResults; | ||
|
||
/** | ||
* Get employee last notification elements | ||
* | ||
* @internal | ||
*/ | ||
final class GetNotificationLastElementsHandler implements GetNotificationLastElementsHandlerInterface | ||
{ | ||
/** | ||
* @param GetNotificationLastElements $query | ||
* | ||
* @return NotificationsResults | ||
* | ||
* {@inheritdoc} | ||
*/ | ||
public function handle(GetNotificationLastElements $query): NotificationsResults | ||
{ | ||
$elements = (new Notification())->getLastElements(); | ||
$results = []; | ||
foreach ($elements as $type => $notifications) { | ||
$notificationsResult = []; | ||
foreach ($notifications['results'] as $notification) { | ||
$notificationsResult[] = new NotificationResult( | ||
$notification['id_order'], | ||
$notification['id_customer'], | ||
$notification['customer_name'], | ||
$notification['id_customer_message'], | ||
$notification['id_customer_thread'], | ||
$notification['customer_view_url'], | ||
$notification['total_paid'], | ||
$notification['carrier'], | ||
$notification['iso_code'], | ||
$notification['company'], | ||
$notification['status'], | ||
$notification['date_add'] | ||
); | ||
} | ||
$results[] = new NotificationsResult($type, $notifications['total'], $notificationsResult); | ||
} | ||
|
||
return new NotificationsResults($results); | ||
} | ||
} |
61 changes: 61 additions & 0 deletions
61
src/Core/Domain/Notification/Command/UpdateEmployeeNotificationLastElementCommand.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,61 @@ | ||
<?php | ||
/** | ||
* 2007-2019 PrestaShop SA and Contributors | ||
* | ||
* NOTICE OF LICENSE | ||
* | ||
* This source file is subject to the Open Software License (OSL 3.0) | ||
* that is bundled with this package in the file LICENSE.txt. | ||
* It is also available through the world-wide-web at this URL: | ||
* https://opensource.org/licenses/OSL-3.0 | ||
* If you did not receive a copy of the license and are unable to | ||
* obtain it through the world-wide-web, please send an email | ||
* to license@prestashop.com so we can send you a copy immediately. | ||
* | ||
* DISCLAIMER | ||
* | ||
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer | ||
* versions in the future. If you wish to customize PrestaShop for your | ||
* needs please refer to https://www.prestashop.com for more information. | ||
* | ||
* @author PrestaShop SA <contact@prestashop.com> | ||
* @copyright 2007-2019 PrestaShop SA and Contributors | ||
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) | ||
* International Registered Trademark & Property of PrestaShop SA | ||
*/ | ||
|
||
namespace PrestaShop\PrestaShop\Core\Domain\Notification\Command; | ||
|
||
use PrestaShop\PrestaShop\Core\Domain\Notification\Exception\TypeException; | ||
use PrestaShop\PrestaShop\Core\Domain\Notification\ValueObject\Type; | ||
|
||
/** | ||
* Updates the last notification element from a given type seen by the employee | ||
*/ | ||
class UpdateEmployeeNotificationLastElementCommand | ||
{ | ||
/** | ||
* @var Type | ||
*/ | ||
private $type; | ||
|
||
/** | ||
* UpdateEmployeeNotificationLastElementCommand constructor. | ||
* | ||
* @param string $type | ||
* | ||
* @throws TypeException | ||
*/ | ||
public function __construct(string $type) | ||
{ | ||
$this->type = new Type($type); | ||
} | ||
|
||
/** | ||
* @return Type | ||
*/ | ||
public function getType() | ||
{ | ||
return $this->type; | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
...ification/CommandHandler/UpdateEmployeeNotificationLastElementCommandHandlerInterface.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,40 @@ | ||
<?php | ||
/** | ||
* 2007-2019 PrestaShop SA and Contributors | ||
* | ||
* NOTICE OF LICENSE | ||
* | ||
* This source file is subject to the Open Software License (OSL 3.0) | ||
* that is bundled with this package in the file LICENSE.txt. | ||
* It is also available through the world-wide-web at this URL: | ||
* https://opensource.org/licenses/OSL-3.0 | ||
* If you did not receive a copy of the license and are unable to | ||
* obtain it through the world-wide-web, please send an email | ||
* to license@prestashop.com so we can send you a copy immediately. | ||
* | ||
* DISCLAIMER | ||
* | ||
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer | ||
* versions in the future. If you wish to customize PrestaShop for your | ||
* needs please refer to https://www.prestashop.com for more information. | ||
* | ||
* @author PrestaShop SA <contact@prestashop.com> | ||
* @copyright 2007-2019 PrestaShop SA and Contributors | ||
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) | ||
* International Registered Trademark & Property of PrestaShop SA | ||
*/ | ||
|
||
namespace PrestaShop\PrestaShop\Core\Domain\Notification\CommandHandler; | ||
|
||
use PrestaShop\PrestaShop\Core\Domain\Notification\Command\UpdateEmployeeNotificationLastElementCommand; | ||
|
||
/** | ||
* Interface for service that handles ACK employee notifications last elements | ||
*/ | ||
interface UpdateEmployeeNotificationLastElementCommandHandlerInterface | ||
{ | ||
/** | ||
* @param UpdateEmployeeNotificationLastElementCommand $command | ||
*/ | ||
public function handle(UpdateEmployeeNotificationLastElementCommand $command); | ||
} |
36 changes: 36 additions & 0 deletions
36
src/Core/Domain/Notification/Exception/NotificationException.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,36 @@ | ||
<?php | ||
/** | ||
* 2007-2019 PrestaShop SA and Contributors | ||
* | ||
* NOTICE OF LICENSE | ||
* | ||
* This source file is subject to the Open Software License (OSL 3.0) | ||
* that is bundled with this package in the file LICENSE.txt. | ||
* It is also available through the world-wide-web at this URL: | ||
* https://opensource.org/licenses/OSL-3.0 | ||
* If you did not receive a copy of the license and are unable to | ||
* obtain it through the world-wide-web, please send an email | ||
* to license@prestashop.com so we can send you a copy immediately. | ||
* | ||
* DISCLAIMER | ||
* | ||
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer | ||
* versions in the future. If you wish to customize PrestaShop for your | ||
* needs please refer to https://www.prestashop.com for more information. | ||
* | ||
* @author PrestaShop SA <contact@prestashop.com> | ||
* @copyright 2007-2019 PrestaShop SA and Contributors | ||
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) | ||
* International Registered Trademark & Property of PrestaShop SA | ||
*/ | ||
|
||
namespace PrestaShop\PrestaShop\Core\Domain\Notification\Exception; | ||
|
||
use PrestaShop\PrestaShop\Core\Domain\Exception\DomainException; | ||
|
||
/** | ||
* Base exception for Notification sub-domain | ||
*/ | ||
class NotificationException extends DomainException | ||
{ | ||
} |
61 changes: 61 additions & 0 deletions
61
src/Core/Domain/Notification/Query/GetNotificationLastElements.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,61 @@ | ||
<?php | ||
/** | ||
* 2007-2019 PrestaShop SA and Contributors | ||
* | ||
* NOTICE OF LICENSE | ||
* | ||
* This source file is subject to the Open Software License (OSL 3.0) | ||
* that is bundled with this package in the file LICENSE.txt. | ||
* It is also available through the world-wide-web at this URL: | ||
* https://opensource.org/licenses/OSL-3.0 | ||
* If you did not receive a copy of the license and are unable to | ||
* obtain it through the world-wide-web, please send an email | ||
* to license@prestashop.com so we can send you a copy immediately. | ||
* | ||
* DISCLAIMER | ||
* | ||
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer | ||
* versions in the future. If you wish to customize PrestaShop for your | ||
* needs please refer to https://www.prestashop.com for more information. | ||
* | ||
* @author PrestaShop SA <contact@prestashop.com> | ||
* @copyright 2007-2019 PrestaShop SA and Contributors | ||
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) | ||
* International Registered Trademark & Property of PrestaShop SA | ||
*/ | ||
|
||
namespace PrestaShop\PrestaShop\Core\Domain\Notification\Query; | ||
|
||
use PrestaShop\PrestaShop\Core\Domain\Employee\Exception\InvalidEmployeeIdException; | ||
use PrestaShop\PrestaShop\Core\Domain\Employee\ValueObject\EmployeeId; | ||
|
||
/** | ||
* This Query return the last Notifications elements | ||
*/ | ||
class GetNotificationLastElements | ||
{ | ||
/** | ||
* @var EmployeeId | ||
*/ | ||
private $employeeId; | ||
|
||
/** | ||
* GetNotificationLastElements constructor. | ||
* | ||
* @param $employeeId | ||
* | ||
* @throws InvalidEmployeeIdException | ||
*/ | ||
public function __construct(int $employeeId) | ||
{ | ||
$this->employeeId = new EmployeeId($employeeId); | ||
} | ||
|
||
/** | ||
* @return EmployeeId | ||
*/ | ||
public function getEmployeeId(): EmployeeId | ||
{ | ||
return $this->employeeId; | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
src/Core/Domain/Notification/QueryHandler/GetNotificationLastElementsHandlerInterface.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 | ||
/** | ||
* 2007-2019 PrestaShop SA and Contributors | ||
* | ||
* NOTICE OF LICENSE | ||
* | ||
* This source file is subject to the Open Software License (OSL 3.0) | ||
* that is bundled with this package in the file LICENSE.txt. | ||
* It is also available through the world-wide-web at this URL: | ||
* https://opensource.org/licenses/OSL-3.0 | ||
* If you did not receive a copy of the license and are unable to | ||
* obtain it through the world-wide-web, please send an email | ||
* to license@prestashop.com so we can send you a copy immediately. | ||
* | ||
* DISCLAIMER | ||
* | ||
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer | ||
* versions in the future. If you wish to customize PrestaShop for your | ||
* needs please refer to https://www.prestashop.com for more information. | ||
* | ||
* @author PrestaShop SA <contact@prestashop.com> | ||
* @copyright 2007-2019 PrestaShop SA and Contributors | ||
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) | ||
* International Registered Trademark & Property of PrestaShop SA | ||
*/ | ||
|
||
namespace PrestaShop\PrestaShop\Core\Domain\Notification\QueryHandler; | ||
|
||
use PrestaShop\PrestaShop\Core\Domain\Notification\Query\GetNotificationLastElements; | ||
use PrestaShop\PrestaShop\Core\Domain\Notification\QueryResult\NotificationsResults; | ||
|
||
/** | ||
* Interface for service that handles notifications last elements request | ||
*/ | ||
interface GetNotificationLastElementsHandlerInterface | ||
{ | ||
/** | ||
* @param GetNotificationLastElements $query | ||
* | ||
* @return NotificationsResults | ||
*/ | ||
public function handle(GetNotificationLastElements $query): NotificationsResults; | ||
} |
Oops, something went wrong.