Skip to content

Migrate "/me" routes to API Platform #14

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

Merged
merged 1 commit into from
May 9, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 0 additions & 58 deletions spec/Command/Customer/UpdateCustomerSpec.php

This file was deleted.

54 changes: 0 additions & 54 deletions spec/Factory/Customer/CustomerViewFactorySpec.php

This file was deleted.

52 changes: 0 additions & 52 deletions spec/Handler/Customer/UpdateCustomerHandlerSpec.php

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

declare(strict_types=1);

namespace Sylius\ShopApiPlugin\ApiPlatform;
namespace Sylius\ShopApiPlugin\ApiPlatform\DataPersister;

use ApiPlatform\Core\DataPersister\DataPersisterInterface;
use Sylius\ShopApiPlugin\Request\CommandRequestInterface;
use Symfony\Component\Messenger\MessageBusInterface;

final class DataPersister implements DataPersisterInterface
final class CommandRequestDataPersister implements DataPersisterInterface
{
private $commandBus;

Expand Down
50 changes: 50 additions & 0 deletions src/ApiPlatform/DataProvider/CustomerItemDataProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php

declare(strict_types=1);

namespace Sylius\ShopApiPlugin\ApiPlatform\DataProvider;

use ApiPlatform\Core\DataProvider\ItemDataProviderInterface;
use ApiPlatform\Core\DataProvider\RestrictedDataProviderInterface;
use Sylius\Component\Core\Model\ShopUserInterface;
use Sylius\Component\Customer\Model\CustomerInterface;
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;

final class CustomerItemDataProvider implements ItemDataProviderInterface, RestrictedDataProviderInterface
{
private $tokenStorage;

public function __construct(TokenStorageInterface $tokenStorage)
{
$this->tokenStorage = $tokenStorage;
}

/**
* {@inheritdoc}
*/
public function supports(string $resourceClass, string $operationName = null, array $context = []): bool
{
return is_a($resourceClass, CustomerInterface::class, true);
}

/**
* {@inheritdoc}
*/
public function getItem(string $resourceClass, $id, string $operationName = null, array $context = []): ?object
{
if ('me' !== $id) {
return null;
}

if (null === $token = $this->tokenStorage->getToken()) {
return null;
}

$user = $token->getUser();
if (!$user instanceof ShopUserInterface) {
return null;
}

return $user->getCustomer();
}
}
1 change: 0 additions & 1 deletion src/Command/Customer/GenerateResetPasswordToken.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

class GenerateResetPasswordToken implements CommandInterface
{
/** @var string */
protected $email;

public function __construct(string $email)
Expand Down
1 change: 0 additions & 1 deletion src/Command/Customer/GenerateVerificationToken.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

class GenerateVerificationToken implements CommandInterface
{
/** @var string */
protected $email;

public function __construct(string $email)
Expand Down
9 changes: 0 additions & 9 deletions src/Command/Customer/RegisterCustomer.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,10 @@

class RegisterCustomer implements CommandInterface
{
/** @var string */
protected $email;

/** @var string */
protected $plainPassword;

/** @var string */
protected $firstName;

/** @var string */
protected $lastName;

/** @var string */
protected $channelCode;

public function __construct(string $email, string $plainPassword, string $firstName, string $lastName, string $channelCode)
Expand Down
3 changes: 0 additions & 3 deletions src/Command/Customer/SendResetPasswordToken.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,7 @@

class SendResetPasswordToken implements CommandInterface
{
/** @var string */
protected $email;

/** @var string */
protected $channelCode;

public function __construct(string $email, string $channelCode)
Expand Down
3 changes: 0 additions & 3 deletions src/Command/Customer/SendVerificationToken.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,7 @@

class SendVerificationToken implements CommandInterface
{
/** @var string */
protected $email;

/** @var string */
protected $channelCode;

public function __construct(string $email, string $channelCode)
Expand Down
77 changes: 0 additions & 77 deletions src/Command/Customer/UpdateCustomer.php

This file was deleted.

1 change: 0 additions & 1 deletion src/Command/Customer/VerifyAccount.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

class VerifyAccount implements CommandInterface
{
/** @var string */
protected $token;

public function __construct(string $token)
Expand Down
Loading