Skip to content

Commit 657ee46

Browse files
committed
feat(rfid): add lookup endpoint to retrieve item info by code
1 parent 088998d commit 657ee46

3 files changed

Lines changed: 37 additions & 2 deletions

File tree

app/Http/Controllers/Api/RfidController.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,26 @@ public function __construct(
1919
protected ItemService $itemService
2020
) {}
2121

22+
/**
23+
* Look up item info by item_code (read-only, no stock change).
24+
*/
25+
public function lookup(string $code): JsonResponse
26+
{
27+
$item = $this->itemService->findByCode($code);
28+
29+
if (! $item) {
30+
return response()->json([
31+
'status' => 'error',
32+
'message' => 'Item not found',
33+
], 404);
34+
}
35+
36+
return response()->json([
37+
'status' => 'success',
38+
'data' => $item,
39+
], 200);
40+
}
41+
2242
/**
2343
* Handle RFID scan and adjust item quantity.
2444
*/

app/Services/ItemService.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,17 @@ protected function deleteImages(Item $item)
221221
}
222222
}
223223

224+
/**
225+
* Find an item by its item_code
226+
*
227+
* @param string $itemCode
228+
* @return Item|null
229+
*/
230+
public function findByCode(string $itemCode): ?Item
231+
{
232+
return $this->itemRepo->findByCode($itemCode);
233+
}
234+
224235
/**
225236
* Adjust item quantity via RFID scan.
226237
* Use action 'add' to increase and 'deduct' to decrease.
@@ -232,7 +243,7 @@ protected function deleteImages(Item $item)
232243
*/
233244
public function adjustQuantityByCode(string $itemCode, string $action, int $quantity): array
234245
{
235-
$item = $this->itemRepo->findByCode($itemCode);
246+
$item = $this->findByCode($itemCode);
236247

237248
if (! $item) {
238249
return ['success' => false, 'message' => 'Item not found'];

routes/groups/rfid.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,11 @@
88
->name('rfid.')
99
->group(function () {
1010

11-
// Scan item by item_code
11+
// Look up item info by item_code (read-only, no stock change)
12+
Route::get('/item/{code}', [RfidController::class, 'lookup'])
13+
->name('lookup');
14+
15+
// Scan item by item_code (adjusts stock)
1216
Route::post('/scan', [RfidController::class, 'scan'])
1317
->name('scan');
1418
});

0 commit comments

Comments
 (0)