From d1bb0e2fdaa6ad51345b782fedd18518f9c55417 Mon Sep 17 00:00:00 2001 From: Igor Rjabinin Date: Thu, 28 Nov 2024 16:06:27 +0100 Subject: [PATCH 1/3] search by id and identifier in API v1 --- app/Http/Controllers/Api/V1/ItemController.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/Http/Controllers/Api/V1/ItemController.php b/app/Http/Controllers/Api/V1/ItemController.php index c264fc52d..e4b24bb1f 100644 --- a/app/Http/Controllers/Api/V1/ItemController.php +++ b/app/Http/Controllers/Api/V1/ItemController.php @@ -41,6 +41,8 @@ class ItemController extends Controller 'box', 'location', 'location.tree', + 'identifier', + 'id', ]; private $rangeables = ['date_earliest', 'date_latest', 'additionals.order']; @@ -303,7 +305,7 @@ protected function createQueryBuilder($q, $filter) if ($q) { $query = Query::multiMatch() - ->fields(['title.*', 'description.*']) + ->fields(['title.*', 'description.*', 'identifier', 'id']) ->query($q); $builder->must($query); } From acc4e0cfc6c5af7d4e7246008e4af35a10367109 Mon Sep 17 00:00:00 2001 From: Igor Rjabinin Date: Thu, 28 Nov 2024 16:27:44 +0100 Subject: [PATCH 2/3] add tests --- tests/Feature/Api/V1/ItemsTest.php | 41 ++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/tests/Feature/Api/V1/ItemsTest.php b/tests/Feature/Api/V1/ItemsTest.php index 20f9e66eb..239e7da4b 100644 --- a/tests/Feature/Api/V1/ItemsTest.php +++ b/tests/Feature/Api/V1/ItemsTest.php @@ -326,4 +326,45 @@ public function test_show() ], ]); } + + public function test_search_by_id() + { + $item = Item::factory()->create(); + app(ItemRepository::class)->refreshIndex(); + + $url = route('api.v1.items.index', [ + 'q' => $item->id, + ]); + + $this->getJson($url)->assertJson([ + 'total' => 1, + 'data' => [ + [ + 'id' => $item->id, + ], + ], + ]); + } + + public function test_search_by_identifier() + { + $item = Item::factory()->create(['identifier' => 'G 3415']); + app(ItemRepository::class)->refreshIndex(); + + $url = route('api.v1.items.index', [ + 'q' => 'G 3415', + ]); + + $this->getJson($url)->assertJson([ + 'total' => 1, + 'data' => [ + [ + 'id' => $item->id, + 'content' => [ + 'identifier' => 'G 3415', + ], + ], + ], + ]); + } } From fa3e951c6bcda86792931e10f8295b1239c741cd Mon Sep 17 00:00:00 2001 From: Igor Rjabinin Date: Thu, 28 Nov 2024 17:09:56 +0100 Subject: [PATCH 3/3] remove identifier and id from filterables in API v1 --- app/Http/Controllers/Api/V1/ItemController.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/app/Http/Controllers/Api/V1/ItemController.php b/app/Http/Controllers/Api/V1/ItemController.php index e4b24bb1f..304c072f0 100644 --- a/app/Http/Controllers/Api/V1/ItemController.php +++ b/app/Http/Controllers/Api/V1/ItemController.php @@ -41,8 +41,6 @@ class ItemController extends Controller 'box', 'location', 'location.tree', - 'identifier', - 'id', ]; private $rangeables = ['date_earliest', 'date_latest', 'additionals.order'];