feat: [bending] 기초자료 복사 API 추가 — 같은 분류의 다음 번호 자동 채번
This commit is contained in:
@@ -96,6 +96,16 @@ public function update(BendingItemUpdateRequest $request, int $id): JsonResponse
|
||||
);
|
||||
}
|
||||
|
||||
public function duplicate(Request $request, int $id): JsonResponse
|
||||
{
|
||||
$this->ensureContext($request);
|
||||
|
||||
return ApiResponse::handle(
|
||||
fn () => new BendingItemResource($this->service->duplicate($id)),
|
||||
__('message.created')
|
||||
);
|
||||
}
|
||||
|
||||
public function destroy(Request $request, int $id): JsonResponse
|
||||
{
|
||||
$this->ensureContext($request);
|
||||
|
||||
@@ -135,6 +135,43 @@ public function update(int $id, array $data): BendingItem
|
||||
return $item;
|
||||
}
|
||||
|
||||
/**
|
||||
* 기초자료 복사 — 같은 분류코드의 다음 번호 자동 채번
|
||||
*/
|
||||
public function duplicate(int $id): BendingItem
|
||||
{
|
||||
$source = BendingItem::findOrFail($id);
|
||||
|
||||
// 분류코드 추출 (BD-CL.001 → CL)
|
||||
preg_match('/^BD-([A-Z]{2})/', $source->code, $m);
|
||||
$prefix = $m[1] ?? 'XX';
|
||||
$newCode = $this->generateCode($prefix);
|
||||
|
||||
return BendingItem::create([
|
||||
'tenant_id' => $source->tenant_id,
|
||||
'code' => $newCode,
|
||||
'item_name' => $source->item_name,
|
||||
'item_sep' => $source->item_sep,
|
||||
'item_bending' => $source->item_bending,
|
||||
'material' => $source->material,
|
||||
'item_spec' => $source->item_spec,
|
||||
'model_name' => $source->model_name,
|
||||
'model_UA' => $source->model_UA,
|
||||
'rail_width' => $source->rail_width,
|
||||
'exit_direction' => $source->exit_direction,
|
||||
'box_width' => $source->box_width,
|
||||
'box_height' => $source->box_height,
|
||||
'front_bottom' => $source->front_bottom,
|
||||
'inspection_door' => $source->inspection_door,
|
||||
'length_code' => $source->length_code,
|
||||
'length_mm' => $source->length_mm,
|
||||
'bending_data' => $source->bending_data,
|
||||
'options' => $source->options,
|
||||
'is_active' => true,
|
||||
'created_by' => $this->apiUserId(),
|
||||
]);
|
||||
}
|
||||
|
||||
public function delete(int $id): bool
|
||||
{
|
||||
$item = BendingItem::findOrFail($id);
|
||||
|
||||
@@ -143,6 +143,7 @@
|
||||
Route::post('', [BendingItemController::class, 'store'])->name('v1.bending-items.store');
|
||||
Route::get('/{id}', [BendingItemController::class, 'show'])->whereNumber('id')->name('v1.bending-items.show');
|
||||
Route::put('/{id}', [BendingItemController::class, 'update'])->whereNumber('id')->name('v1.bending-items.update');
|
||||
Route::post('/{id}/duplicate', [BendingItemController::class, 'duplicate'])->whereNumber('id')->name('v1.bending-items.duplicate');
|
||||
Route::delete('/{id}', [BendingItemController::class, 'destroy'])->whereNumber('id')->name('v1.bending-items.destroy');
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user