feat(quote-formula): 매핑/품목 관리 UI 구현 (Phase 2, 3)
Phase 2 - 매핑(Mapping) 관리: - QuoteFormulaMappingController, QuoteFormulaMappingService 추가 - mappings-tab.blade.php 뷰 생성 - 매핑 CRUD 및 순서 변경 API Phase 3 - 품목(Item) 관리: - QuoteFormulaItemController, QuoteFormulaItemService 추가 - items-tab.blade.php 뷰 생성 - 품목 CRUD 및 순서 변경 API - 수량식/단가식 입력 지원 공통: - edit.blade.php에 매핑/품목 탭 연동 - routes/api.php에 API 엔드포인트 추가
This commit is contained in:
@@ -0,0 +1,153 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api\Admin\Quote;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Services\Quote\QuoteFormulaItemService;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class QuoteFormulaItemController extends Controller
|
||||
{
|
||||
public function __construct(
|
||||
private readonly QuoteFormulaItemService $itemService
|
||||
) {}
|
||||
|
||||
/**
|
||||
* 품목 목록 조회
|
||||
*/
|
||||
public function index(int $formulaId): JsonResponse
|
||||
{
|
||||
$items = $this->itemService->getItemsByFormula($formulaId);
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'data' => $items,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 품목 상세 조회
|
||||
*/
|
||||
public function show(int $formulaId, int $itemId): JsonResponse
|
||||
{
|
||||
// 수식 소속 확인
|
||||
if (! $this->itemService->belongsToFormula($itemId, $formulaId)) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => '해당 수식에 속하지 않는 품목입니다.',
|
||||
], 404);
|
||||
}
|
||||
|
||||
$item = $this->itemService->getItemById($itemId);
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'data' => $item,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 품목 생성
|
||||
*/
|
||||
public function store(Request $request, int $formulaId): JsonResponse
|
||||
{
|
||||
$validated = $request->validate([
|
||||
'item_code' => 'required|string|max:50',
|
||||
'item_name' => 'required|string|max:200',
|
||||
'specification' => 'nullable|string|max:200',
|
||||
'unit' => 'nullable|string|max:20',
|
||||
'quantity_formula' => 'nullable|string|max:500',
|
||||
'unit_price_formula' => 'nullable|string|max:500',
|
||||
'sort_order' => 'nullable|integer|min:0',
|
||||
]);
|
||||
|
||||
$item = $this->itemService->createItem($formulaId, $validated);
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'message' => '품목이 추가되었습니다.',
|
||||
'data' => $item,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 품목 수정
|
||||
*/
|
||||
public function update(Request $request, int $formulaId, int $itemId): JsonResponse
|
||||
{
|
||||
// 수식 소속 확인
|
||||
if (! $this->itemService->belongsToFormula($itemId, $formulaId)) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => '해당 수식에 속하지 않는 품목입니다.',
|
||||
], 404);
|
||||
}
|
||||
|
||||
$validated = $request->validate([
|
||||
'item_code' => 'nullable|string|max:50',
|
||||
'item_name' => 'nullable|string|max:200',
|
||||
'specification' => 'nullable|string|max:200',
|
||||
'unit' => 'nullable|string|max:20',
|
||||
'quantity_formula' => 'nullable|string|max:500',
|
||||
'unit_price_formula' => 'nullable|string|max:500',
|
||||
]);
|
||||
|
||||
$item = $this->itemService->updateItem($itemId, $validated);
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'message' => '품목이 수정되었습니다.',
|
||||
'data' => $item,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 품목 삭제
|
||||
*/
|
||||
public function destroy(int $formulaId, int $itemId): JsonResponse
|
||||
{
|
||||
// 수식 소속 확인
|
||||
if (! $this->itemService->belongsToFormula($itemId, $formulaId)) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => '해당 수식에 속하지 않는 품목입니다.',
|
||||
], 404);
|
||||
}
|
||||
|
||||
$this->itemService->deleteItem($itemId);
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'message' => '품목이 삭제되었습니다.',
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 순서 변경
|
||||
*/
|
||||
public function reorder(Request $request, int $formulaId): JsonResponse
|
||||
{
|
||||
$validated = $request->validate([
|
||||
'item_ids' => 'required|array',
|
||||
'item_ids.*' => 'integer',
|
||||
]);
|
||||
|
||||
// 모든 품목이 해당 수식에 속하는지 확인
|
||||
foreach ($validated['item_ids'] as $itemId) {
|
||||
if (! $this->itemService->belongsToFormula($itemId, $formulaId)) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => '유효하지 않은 품목 ID가 포함되어 있습니다.',
|
||||
], 400);
|
||||
}
|
||||
}
|
||||
|
||||
$this->itemService->reorder($validated['item_ids']);
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'message' => '순서가 변경되었습니다.',
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user