Skip to content

Commit

Permalink
Code review fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
TomaszLach2 committed Jul 29, 2024
1 parent 6a2923d commit 3b15b89
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 15 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/.idea
/vendor/
/node_modules/
/composer.lock
Expand Down
14 changes: 7 additions & 7 deletions src/Form/Model/SendPushNotificationFormModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,27 @@

namespace SpearDevs\SyliusPushNotificationsPlugin\Form\Model;

use SpearDevs\SyliusPushNotificationsPlugin\Validator\Constraints\PushNotificationUser;
use SpearDevs\SyliusPushNotificationsPlugin\Validator\Constraints\PushNotificationUserSubscriptionExists;
use Sylius\Component\Core\Model\ChannelInterface;
use Sylius\Component\Customer\Model\CustomerGroupInterface;
use Symfony\Component\Validator\Constraints as Assert;

/** @PushNotificationUser() */
/** @PushNotificationUserSubscriptionExists() */
final class SendPushNotificationFormModel
{
/** @Assert\NotBlank() */
public ?string $title = null;
public string $title;

/** @Assert\NotBlank() */
public ?string $body = null;
public string $body;

/** @Assert\NotBlank() */
public ?ChannelInterface $channel = null;
public ChannelInterface $channel;

public ?string $receiver = null;
public string $receiver;

public ?CustomerGroupInterface $group = null;

/** @Assert\Email() */
public ?string $userEmail = null;
public string $userEmail;
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
/**
* @Annotation
*/
class PushNotificationUser extends Constraint
class PushNotificationUserSubscriptionExists extends Constraint
{
public string $message = 'push_notifications.send.user_subscription_not_exist';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
use Symfony\Component\Validator\ConstraintValidator;
use Traversable;

final class PushNotificationUserValidator extends ConstraintValidator
final class PushNotificationUserSubscriptionExistsValidator extends ConstraintValidator
{
public function __construct(
private UserSubscriptionRepositoryInterface $userSubscriptionRepository,
Expand All @@ -24,7 +24,7 @@ public function __construct(
*/
public function validate($value, Constraint $constraint): void
{
if (!$constraint instanceof PushNotificationUser) {
if (!$constraint instanceof PushNotificationUserSubscriptionExists) {
throw new UnexpectedTypeException($constraint, PushNotificationUser::class);
}

Expand Down
6 changes: 3 additions & 3 deletions src/WebPushSender/WebPushSender.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,17 +51,17 @@ public function sendWebPush(SendPushNotificationFormModel $sendPushNotificationF
$pushContent = $sendPushNotificationFormModel->body;
$receiver = $sendPushNotificationFormModel->receiver;
$channel = $sendPushNotificationFormModel->channel;
$userEmail = $sendPushNotificationFormModel->userEmail;
$customerGroup = $sendPushNotificationFormModel->group;

$webPush = $this->webPushFactory->create($this->orderParameterMapper, null, null, $pushTitle, $pushContent);

if ($receiver === self::USER_RECEIVER) {
$userEmail = $sendPushNotificationFormModel->userEmail;
$this->sendToUser($webPush, $channel, $userEmail);
}

if ($receiver === self::GROUP_RECEIVER) {
$this->sendToGroup($webPush, $channel, $customerGroup);
$customerGroup = $sendPushNotificationFormModel->group;
$this->sendToGroup($webPush, $channel, $customerGroup?->getName());
}
}

Expand Down
2 changes: 1 addition & 1 deletion translations/validators.en.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
push_notifications:
send:
user_subscription_not_exist: The user with the provided email address has not consented to receiving push notifications.
user_subscription_not_exist: The user with the provided email address do not consent to receive push notifications.

0 comments on commit 3b15b89

Please sign in to comment.