Skip to content
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

[API] Product endpoint fixes #16413

Merged
merged 3 commits into from
Jun 17, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Move processor to delete endpoint
  • Loading branch information
mpysiak committed Jun 17, 2024
commit 74dea02e7d3aedff1b06e0b6856806fc9ab93670
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="https://api-platform.com/schema/metadata/resources-3.0 https://api-platform.com/schema/metadata/resources-3.0.xsd"
>
<resource class="Sylius\Component\Core\Model\Product" shortName="Product" processor="sylius_api.state_processor.delete.product">
<resource class="Sylius\Component\Core\Model\Product" shortName="Product">
<validationContext>
<values>
<value name="groups">
Expand Down Expand Up @@ -271,7 +271,7 @@
</normalizationContext>
</operation>

<operation class="ApiPlatform\Metadata\Delete" uriTemplate="/admin/products/{code}" />
<operation class="ApiPlatform\Metadata\Delete" uriTemplate="/admin/products/{code}" processor="sylius_api.state_processor.delete.product"/>

</operations>
</resource>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@
</service>

<service id="sylius_api.state_processor.delete.product" class="Sylius\Bundle\ApiBundle\StateProcessor\Delete\ProductProcessor">
<argument type="service" id="api_platform.doctrine.orm.state.persist_processor" />
<argument type="service" id="api_platform.doctrine.orm.state.remove_processor" />
<tag name="api_platform.state_processor" />
</service>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
final readonly class ProductProcessor implements ProcessorInterface
{
public function __construct(
private ProcessorInterface $persistProcessor,
private ProcessorInterface $removeProcessor,
) {
}
Expand All @@ -36,14 +35,15 @@ public function process(mixed $data, Operation $operation, array $uriVariables =
{
Assert::isInstanceOf($data, ProductInterface::class);

if ($operation instanceof DeleteOperationInterface) {
try {
return $this->removeProcessor->process($data, $operation, $uriVariables, $context);
} catch (ForeignKeyConstraintViolationException) {
throw new ProductCannotBeRemoved();
}
if (!$operation instanceof DeleteOperationInterface) {
return;
GSadee marked this conversation as resolved.
Show resolved Hide resolved
}
mpysiak marked this conversation as resolved.
Show resolved Hide resolved
Assert::isInstanceOf($operation, DeleteOperationInterface::class);
GSadee marked this conversation as resolved.
Show resolved Hide resolved

return $this->persistProcessor->process($data, $operation, $uriVariables, $context);
try {
return $this->removeProcessor->process($data, $operation, $uriVariables, $context);
} catch (ForeignKeyConstraintViolationException) {
throw new ProductCannotBeRemoved();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,24 +25,14 @@ final class ProductProcessorSpec extends ObjectBehavior
{
function let(ProcessorInterface $persistProcessor, ProcessorInterface $removeProcessor): void
{
$this->beConstructedWith($persistProcessor, $removeProcessor);
$this->beConstructedWith($removeProcessor);
}

function it_is_a_processor_interface(): void
{
$this->shouldImplement(ProcessorInterface::class);
}

public function it_processes_persist_operation(
ProcessorInterface $persistProcessor,
Operation $operation,
ProductInterface $product,
) {
$persistProcessor->process($product, $operation, [], [])->willReturn($product);

$this->process($product, $operation, [], [])->shouldReturn($product);
}

public function it_processes_remove_operation(
ProcessorInterface $removeProcessor,
Operation $operation,
Expand Down
Loading