From 3ed27f6c0f0ffc042fd74e0fc165f4700543e24d Mon Sep 17 00:00:00 2001 From: Niklas <44636701+MayNiklas@users.noreply.github.com> Date: Sat, 7 Mar 2026 19:31:47 +0100 Subject: [PATCH] /api/part_lots: add user_barcode filter (#1280) * /api/part_lots: add user_barcode filter * support LIKE filtering for part lot user_barcode --- src/Entity/Parts/PartLot.php | 2 +- tests/API/Endpoints/PartLotsEndpointTest.php | 26 ++++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/src/Entity/Parts/PartLot.php b/src/Entity/Parts/PartLot.php index 53ecd3d5..f7224843 100644 --- a/src/Entity/Parts/PartLot.php +++ b/src/Entity/Parts/PartLot.php @@ -81,7 +81,7 @@ use Symfony\Component\Validator\Context\ExecutionContextInterface; denormalizationContext: ['groups' => ['part_lot:write', 'api:basic:write'], 'openapi_definition_name' => 'Write'], )] #[ApiFilter(PropertyFilter::class)] -#[ApiFilter(LikeFilter::class, properties: ["description", "comment"])] +#[ApiFilter(LikeFilter::class, properties: ["description", "comment", "user_barcode"])] #[ApiFilter(DateFilter::class, strategy: DateFilterInterface::EXCLUDE_NULL)] #[ApiFilter(BooleanFilter::class, properties: ['instock_unknown', 'needs_refill'])] #[ApiFilter(RangeFilter::class, properties: ['amount'])] diff --git a/tests/API/Endpoints/PartLotsEndpointTest.php b/tests/API/Endpoints/PartLotsEndpointTest.php index 70f1f9ab..0d48d1e7 100644 --- a/tests/API/Endpoints/PartLotsEndpointTest.php +++ b/tests/API/Endpoints/PartLotsEndpointTest.php @@ -47,6 +47,32 @@ final class PartLotsEndpointTest extends CrudEndpointTestCase $this->_testGetItem(2); } + public function testFilterByUserBarcode(): void + { + $response = self::createAuthenticatedClient()->request('GET', '/api/part_lots?user_barcode=lot2_vendor_barcode'); + + self::assertResponseIsSuccessful(); + self::assertJsonContains([ + 'hydra:totalItems' => 1, + ]); + + $json = $response->toArray(); + self::assertSame('/api/part_lots/2', $json['hydra:member'][0]['@id']); + } + + public function testFilterByUserBarcodeUsingWildcard(): void + { + $response = self::createAuthenticatedClient()->request('GET', '/api/part_lots?user_barcode=lot2_%'); + + self::assertResponseIsSuccessful(); + self::assertJsonContains([ + 'hydra:totalItems' => 1, + ]); + + $json = $response->toArray(); + self::assertSame('/api/part_lots/2', $json['hydra:member'][0]['@id']); + } + public function testCreateItem(): void { $this->_testPostItem([