From a71dab791addcbc2ea50e2576ecc00386b2cd780 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EB=B3=B4=EA=B3=A4?= Date: Sat, 21 Mar 2026 11:49:06 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20[bending]=20=EA=B8=B0=EC=B4=88=EC=9E=90?= =?UTF-8?q?=EB=A3=8C=20=EB=B3=B5=EC=82=AC=20API=20=EC=B6=94=EA=B0=80=20?= =?UTF-8?q?=E2=80=94=20=EA=B0=99=EC=9D=80=20=EB=B6=84=EB=A5=98=EC=9D=98=20?= =?UTF-8?q?=EB=8B=A4=EC=9D=8C=20=EB=B2=88=ED=98=B8=20=EC=9E=90=EB=8F=99=20?= =?UTF-8?q?=EC=B1=84=EB=B2=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Api/V1/BendingItemController.php | 10 +++++ app/Services/BendingItemService.php | 37 +++++++++++++++++++ routes/api/v1/production.php | 1 + 3 files changed, 48 insertions(+) diff --git a/app/Http/Controllers/Api/V1/BendingItemController.php b/app/Http/Controllers/Api/V1/BendingItemController.php index 2261768d..56f9ad89 100644 --- a/app/Http/Controllers/Api/V1/BendingItemController.php +++ b/app/Http/Controllers/Api/V1/BendingItemController.php @@ -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); diff --git a/app/Services/BendingItemService.php b/app/Services/BendingItemService.php index d539e6dc..c1572e17 100644 --- a/app/Services/BendingItemService.php +++ b/app/Services/BendingItemService.php @@ -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); diff --git a/routes/api/v1/production.php b/routes/api/v1/production.php index 6f589afd..c177fc62 100644 --- a/routes/api/v1/production.php +++ b/routes/api/v1/production.php @@ -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'); });