feat: H-2 재고 현황 API 구현
- StockController: 재고 조회 및 통계 API - StockService: 재고 비즈니스 로직 - Stock, StockLot 모델: 재고/로트 관리 - Swagger 문서화 - stocks, stock_lots 테이블 마이그레이션 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
71
app/Http/Controllers/Api/V1/StockController.php
Normal file
71
app/Http/Controllers/Api/V1/StockController.php
Normal file
@@ -0,0 +1,71 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api\V1;
|
||||
|
||||
use App\Helpers\ApiResponse;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Services\StockService;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class StockController extends Controller
|
||||
{
|
||||
public function __construct(
|
||||
private readonly StockService $service
|
||||
) {}
|
||||
|
||||
/**
|
||||
* 재고 목록 조회
|
||||
*/
|
||||
public function index(Request $request): JsonResponse
|
||||
{
|
||||
$params = $request->only([
|
||||
'search',
|
||||
'item_type',
|
||||
'status',
|
||||
'location',
|
||||
'sort_by',
|
||||
'sort_dir',
|
||||
'per_page',
|
||||
'page',
|
||||
]);
|
||||
|
||||
$stocks = $this->service->index($params);
|
||||
|
||||
return ApiResponse::success($stocks, __('message.fetched'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 재고 통계 조회
|
||||
*/
|
||||
public function stats(): JsonResponse
|
||||
{
|
||||
$stats = $this->service->stats();
|
||||
|
||||
return ApiResponse::success($stats, __('message.fetched'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 재고 상세 조회 (LOT 포함)
|
||||
*/
|
||||
public function show(int $id): JsonResponse
|
||||
{
|
||||
try {
|
||||
$stock = $this->service->show($id);
|
||||
|
||||
return ApiResponse::success($stock, __('message.fetched'));
|
||||
} catch (\Illuminate\Database\Eloquent\ModelNotFoundException $e) {
|
||||
return ApiResponse::error(__('error.stock.not_found'), 404);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 품목유형별 통계 조회
|
||||
*/
|
||||
public function statsByItemType(): JsonResponse
|
||||
{
|
||||
$stats = $this->service->statsByItemType();
|
||||
|
||||
return ApiResponse::success($stats, __('message.fetched'));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user