Skip to content

Commit

Permalink
Merge pull request #15965 from atomiix/notification-CQRS
Browse files Browse the repository at this point in the history
Implements CQRS on Notifications
  • Loading branch information
matks committed Oct 31, 2019
2 parents 05a5147 + a87cbf6 commit 6e60f22
Show file tree
Hide file tree
Showing 13 changed files with 888 additions and 4 deletions.
@@ -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());
}
}
@@ -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);
}
}
@@ -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;
}
}
@@ -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 src/Core/Domain/Notification/Exception/NotificationException.php
@@ -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 src/Core/Domain/Notification/Query/GetNotificationLastElements.php
@@ -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;
}
}
@@ -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;
}

0 comments on commit 6e60f22

Please sign in to comment.