From d72f200c987f13887ee347456c8f91907581e4ee Mon Sep 17 00:00:00 2001 From: milwoz Date: Wed, 24 Aug 2022 14:27:33 +0200 Subject: [PATCH 1/2] Added new repository method --- src/Repository/WishlistRepository.php | 18 +++++++++++++++--- src/Repository/WishlistRepositoryInterface.php | 2 ++ 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/Repository/WishlistRepository.php b/src/Repository/WishlistRepository.php index fd9dd8ab..ecae1523 100644 --- a/src/Repository/WishlistRepository.php +++ b/src/Repository/WishlistRepository.php @@ -25,7 +25,7 @@ public function findOneByShopUser(ShopUserInterface $shopUser): ?WishlistInterfa ->getQuery() ->setMaxResults(1) ->getOneOrNullResult() - ; + ; } public function findByToken(string $token): ?WishlistInterface @@ -36,7 +36,7 @@ public function findByToken(string $token): ?WishlistInterface ->getQuery() ->setMaxResults(1) ->getOneOrNullResult() - ; + ; } public function findAllByToken(string $token): ?array @@ -104,7 +104,7 @@ public function findAllByAnonymousAndChannel(?string $token, ChannelInterface $c ->andWhere('o.channel = :channel') ->andWhere('o.shopUser IS NULL') ->setParameter('channel', $channel) - ; + ; if (null !== $token) { $qb @@ -128,4 +128,16 @@ public function findOneByTokenAndName(string $token, string $name): ?WishlistInt ; } + public function findOneByShopUserAndName(ShopUserInterface $shopUser, string $name): ?WishlistInterface + { + return $this->createQueryBuilder('o') + ->where('o.shopUser = :shopUser') + ->andWhere('o.name =:name') + ->setParameter('shopUser', $shopUser) + ->setParameter('name', $name) + ->getQuery() + ->setMaxResults(1) + ->getOneOrNullResult() + ; + } } diff --git a/src/Repository/WishlistRepositoryInterface.php b/src/Repository/WishlistRepositoryInterface.php index 1aa99792..dc59b964 100644 --- a/src/Repository/WishlistRepositoryInterface.php +++ b/src/Repository/WishlistRepositoryInterface.php @@ -37,4 +37,6 @@ public function findOneByShopUserAndChannel( public function findAllByAnonymousAndChannel(?string $token, ChannelInterface $channel): ?array; public function findOneByTokenAndName(string $token, string $name): ?WishlistInterface; + + public function findOneByShopUserAndName(ShopUserInterface $shopUser, string $name): ?WishlistInterface; } From 15544d5fd34f51177d9ff326713df4083cadd60d Mon Sep 17 00:00:00 2001 From: milwoz Date: Wed, 24 Aug 2022 14:27:46 +0200 Subject: [PATCH 2/2] Added new validation for creating wishlists --- src/CommandHandler/Wishlist/CreateNewWishlistHandler.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/CommandHandler/Wishlist/CreateNewWishlistHandler.php b/src/CommandHandler/Wishlist/CreateNewWishlistHandler.php index 898e7bad..43050f65 100644 --- a/src/CommandHandler/Wishlist/CreateNewWishlistHandler.php +++ b/src/CommandHandler/Wishlist/CreateNewWishlistHandler.php @@ -72,7 +72,11 @@ public function __invoke(CreateNewWishlist $createNewWishlist): void $wishlist->setChannel($channel); } - $wishlists = $this->wishlistRepository->findAllByToken($wishlistCookieToken); + if ($user instanceof ShopUserInterface) { + $wishlists = $this->wishlistRepository->findAllByShopUser($user->getId()); + } else { + $wishlists = $this->wishlistRepository->findAllByAnonymous($wishlistCookieToken); + } /** @var WishlistInterface $wishlist */ foreach ($wishlists as $newWishlist) {