feat: H-3 출하 관리 API 구현

- ShipmentController: 출하 CRUD 및 상태 관리 API
- ShipmentService: 출하 비즈니스 로직
- Shipment, ShipmentItem 모델
- FormRequest 검증 클래스
- Swagger 문서화
- shipments, shipment_items 테이블 마이그레이션

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
2025-12-26 15:46:07 +09:00
parent 5ec201b985
commit aca0902c26
10 changed files with 1808 additions and 0 deletions

View File

@@ -0,0 +1,164 @@
<?php
namespace App\Http\Controllers\Api\V1;
use App\Helpers\ApiResponse;
use App\Http\Controllers\Controller;
use App\Http\Requests\Shipment\ShipmentStoreRequest;
use App\Http\Requests\Shipment\ShipmentUpdateRequest;
use App\Http\Requests\Shipment\ShipmentUpdateStatusRequest;
use App\Services\ShipmentService;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
class ShipmentController extends Controller
{
public function __construct(
private readonly ShipmentService $service
) {}
/**
* 출하 목록 조회
*/
public function index(Request $request): JsonResponse
{
$params = $request->only([
'search',
'status',
'priority',
'delivery_method',
'scheduled_from',
'scheduled_to',
'can_ship',
'deposit_confirmed',
'sort_by',
'sort_dir',
'per_page',
'page',
]);
$shipments = $this->service->index($params);
return ApiResponse::success($shipments, __('message.fetched'));
}
/**
* 출하 통계 조회
*/
public function stats(): JsonResponse
{
$stats = $this->service->stats();
return ApiResponse::success($stats, __('message.fetched'));
}
/**
* 상태별 통계 조회 (탭용)
*/
public function statsByStatus(): JsonResponse
{
$stats = $this->service->statsByStatus();
return ApiResponse::success($stats, __('message.fetched'));
}
/**
* 출하 상세 조회
*/
public function show(int $id): JsonResponse
{
try {
$shipment = $this->service->show($id);
return ApiResponse::success($shipment, __('message.fetched'));
} catch (\Illuminate\Database\Eloquent\ModelNotFoundException $e) {
return ApiResponse::error(__('error.shipment.not_found'), 404);
}
}
/**
* 출하 생성
*/
public function store(ShipmentStoreRequest $request): JsonResponse
{
$shipment = $this->service->store($request->validated());
return ApiResponse::success($shipment, __('message.created'), 201);
}
/**
* 출하 수정
*/
public function update(ShipmentUpdateRequest $request, int $id): JsonResponse
{
try {
$shipment = $this->service->update($id, $request->validated());
return ApiResponse::success($shipment, __('message.updated'));
} catch (\Illuminate\Database\Eloquent\ModelNotFoundException $e) {
return ApiResponse::error(__('error.shipment.not_found'), 404);
}
}
/**
* 출하 상태 변경
*/
public function updateStatus(ShipmentUpdateStatusRequest $request, int $id): JsonResponse
{
try {
$shipment = $this->service->updateStatus(
$id,
$request->validated('status'),
$request->validated()
);
return ApiResponse::success($shipment, __('message.updated'));
} catch (\Illuminate\Database\Eloquent\ModelNotFoundException $e) {
return ApiResponse::error(__('error.shipment.not_found'), 404);
}
}
/**
* 출하 삭제
*/
public function destroy(int $id): JsonResponse
{
try {
$this->service->delete($id);
return ApiResponse::success(null, __('message.deleted'));
} catch (\Illuminate\Database\Eloquent\ModelNotFoundException $e) {
return ApiResponse::error(__('error.shipment.not_found'), 404);
}
}
/**
* LOT 옵션 조회
*/
public function lotOptions(): JsonResponse
{
$options = $this->service->getLotOptions();
return ApiResponse::success($options, __('message.fetched'));
}
/**
* 물류사 옵션 조회
*/
public function logisticsOptions(): JsonResponse
{
$options = $this->service->getLogisticsOptions();
return ApiResponse::success($options, __('message.fetched'));
}
/**
* 차량 톤수 옵션 조회
*/
public function vehicleTonnageOptions(): JsonResponse
{
$options = $this->service->getVehicleTonnageOptions();
return ApiResponse::success($options, __('message.fetched'));
}
}

View File

@@ -0,0 +1,80 @@
<?php
namespace App\Http\Requests\Shipment;
use Illuminate\Foundation\Http\FormRequest;
class ShipmentStoreRequest extends FormRequest
{
public function authorize(): bool
{
return true;
}
public function rules(): array
{
return [
// 기본 정보
'shipment_no' => 'nullable|string|max:50',
'lot_no' => 'nullable|string|max:50',
'order_id' => 'nullable|integer|exists:orders,id',
'scheduled_date' => 'required|date',
'status' => 'nullable|in:scheduled,ready,shipping,completed',
'priority' => 'nullable|in:urgent,normal,low',
'delivery_method' => 'nullable|in:pickup,direct,logistics',
// 발주처/배송 정보
'client_id' => 'nullable|integer|exists:clients,id',
'customer_name' => 'nullable|string|max:100',
'site_name' => 'nullable|string|max:100',
'delivery_address' => 'nullable|string|max:255',
'receiver' => 'nullable|string|max:50',
'receiver_contact' => 'nullable|string|max:50',
// 상태 플래그
'can_ship' => 'nullable|boolean',
'deposit_confirmed' => 'nullable|boolean',
'invoice_issued' => 'nullable|boolean',
'customer_grade' => 'nullable|string|max:20',
// 상차 정보
'loading_manager' => 'nullable|string|max:50',
'loading_time' => 'nullable|date',
// 물류/배차 정보
'logistics_company' => 'nullable|string|max:50',
'vehicle_tonnage' => 'nullable|string|max:20',
'shipping_cost' => 'nullable|numeric|min:0',
// 차량/운전자 정보
'vehicle_no' => 'nullable|string|max:20',
'driver_name' => 'nullable|string|max:50',
'driver_contact' => 'nullable|string|max:50',
'expected_arrival' => 'nullable|date',
// 기타
'remarks' => 'nullable|string',
// 출하 품목
'items' => 'nullable|array',
'items.*.seq' => 'nullable|integer|min:1',
'items.*.item_code' => 'nullable|string|max:50',
'items.*.item_name' => 'required|string|max:100',
'items.*.floor_unit' => 'nullable|string|max:50',
'items.*.specification' => 'nullable|string|max:100',
'items.*.quantity' => 'nullable|numeric|min:0',
'items.*.unit' => 'nullable|string|max:20',
'items.*.lot_no' => 'nullable|string|max:50',
'items.*.stock_lot_id' => 'nullable|integer|exists:stock_lots,id',
'items.*.remarks' => 'nullable|string',
];
}
public function messages(): array
{
return [
'scheduled_date.required' => __('validation.required', ['attribute' => '출고예정일']),
'items.*.item_name.required' => __('validation.required', ['attribute' => '품목명']),
];
}
}

View File

@@ -0,0 +1,70 @@
<?php
namespace App\Http\Requests\Shipment;
use Illuminate\Foundation\Http\FormRequest;
class ShipmentUpdateRequest extends FormRequest
{
public function authorize(): bool
{
return true;
}
public function rules(): array
{
return [
// 기본 정보
'lot_no' => 'nullable|string|max:50',
'order_id' => 'nullable|integer|exists:orders,id',
'scheduled_date' => 'nullable|date',
'priority' => 'nullable|in:urgent,normal,low',
'delivery_method' => 'nullable|in:pickup,direct,logistics',
// 발주처/배송 정보
'client_id' => 'nullable|integer|exists:clients,id',
'customer_name' => 'nullable|string|max:100',
'site_name' => 'nullable|string|max:100',
'delivery_address' => 'nullable|string|max:255',
'receiver' => 'nullable|string|max:50',
'receiver_contact' => 'nullable|string|max:50',
// 상태 플래그
'can_ship' => 'nullable|boolean',
'deposit_confirmed' => 'nullable|boolean',
'invoice_issued' => 'nullable|boolean',
'customer_grade' => 'nullable|string|max:20',
// 상차 정보
'loading_manager' => 'nullable|string|max:50',
'loading_time' => 'nullable|date',
// 물류/배차 정보
'logistics_company' => 'nullable|string|max:50',
'vehicle_tonnage' => 'nullable|string|max:20',
'shipping_cost' => 'nullable|numeric|min:0',
// 차량/운전자 정보
'vehicle_no' => 'nullable|string|max:20',
'driver_name' => 'nullable|string|max:50',
'driver_contact' => 'nullable|string|max:50',
'expected_arrival' => 'nullable|date',
// 기타
'remarks' => 'nullable|string',
// 출하 품목
'items' => 'nullable|array',
'items.*.seq' => 'nullable|integer|min:1',
'items.*.item_code' => 'nullable|string|max:50',
'items.*.item_name' => 'required|string|max:100',
'items.*.floor_unit' => 'nullable|string|max:50',
'items.*.specification' => 'nullable|string|max:100',
'items.*.quantity' => 'nullable|numeric|min:0',
'items.*.unit' => 'nullable|string|max:20',
'items.*.lot_no' => 'nullable|string|max:50',
'items.*.stock_lot_id' => 'nullable|integer|exists:stock_lots,id',
'items.*.remarks' => 'nullable|string',
];
}
}

View File

@@ -0,0 +1,36 @@
<?php
namespace App\Http\Requests\Shipment;
use Illuminate\Foundation\Http\FormRequest;
class ShipmentUpdateStatusRequest extends FormRequest
{
public function authorize(): bool
{
return true;
}
public function rules(): array
{
return [
'status' => 'required|in:scheduled,ready,shipping,completed',
// 상태별 추가 데이터
'loading_time' => 'nullable|date',
'loading_completed_at' => 'nullable|date',
'vehicle_no' => 'nullable|string|max:20',
'driver_name' => 'nullable|string|max:50',
'driver_contact' => 'nullable|string|max:50',
'confirmed_arrival' => 'nullable|date',
];
}
public function messages(): array
{
return [
'status.required' => __('validation.required', ['attribute' => '상태']),
'status.in' => __('validation.in', ['attribute' => '상태']),
];
}
}