From 8b78d62068cee78092f0baaa3f55b805100c49c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B6=8C=ED=98=81=EC=84=B1?= Date: Wed, 11 Feb 2026 15:58:35 +0900 Subject: [PATCH] =?UTF-8?q?feat(API):=20=EA=B3=B5=EC=A0=95=20options=20JSO?= =?UTF-8?q?N=20=EC=BB=AC=EB=9F=BC=20=EB=A7=88=EC=9D=B4=EA=B7=B8=EB=A0=88?= =?UTF-8?q?=EC=9D=B4=EC=85=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - needs_work_log 개별 컬럼 → options JSON 구조로 전환 - StoreProcessRequest, UpdateProcessRequest 유효성 규칙 갱신 - Process 모델 $fillable, $casts 갱신 Co-Authored-By: Claude Opus 4.6 --- .../V1/Process/StoreProcessRequest.php | 8 ++- .../V1/Process/UpdateProcessRequest.php | 8 ++- app/Models/Process.php | 4 +- ..._02_11_200001_add_options_to_processes.php | 59 +++++++++++++++++++ 4 files changed, 73 insertions(+), 6 deletions(-) create mode 100644 database/migrations/2026_02_11_200001_add_options_to_processes.php diff --git a/app/Http/Requests/V1/Process/StoreProcessRequest.php b/app/Http/Requests/V1/Process/StoreProcessRequest.php index d2794a8..68eda98 100644 --- a/app/Http/Requests/V1/Process/StoreProcessRequest.php +++ b/app/Http/Requests/V1/Process/StoreProcessRequest.php @@ -20,8 +20,10 @@ public function rules(): array 'department' => ['nullable', 'string', 'max:100'], 'work_log_template' => ['nullable', 'string', 'max:100'], 'document_template_id' => ['nullable', 'integer', 'exists:document_templates,id'], - 'needs_work_log' => ['nullable', 'boolean'], 'work_log_template_id' => ['nullable', 'integer', 'exists:document_templates,id'], + 'options' => ['nullable', 'array'], + 'options.needs_inspection' => ['nullable', 'boolean'], + 'options.needs_work_log' => ['nullable', 'boolean'], 'required_workers' => ['nullable', 'integer', 'min:1'], 'equipment_info' => ['nullable', 'string', 'max:255'], 'work_steps' => ['nullable'], @@ -52,8 +54,10 @@ public function attributes(): array 'department' => '담당부서', 'work_log_template' => '작업일지 양식', 'document_template_id' => '중간검사 양식', - 'needs_work_log' => '작업일지 여부', 'work_log_template_id' => '작업일지 양식 ID', + 'options' => '공정 설정', + 'options.needs_inspection' => '중간검사 여부', + 'options.needs_work_log' => '작업일지 여부', 'required_workers' => '필요인원', 'equipment_info' => '설비정보', 'work_steps' => '작업단계', diff --git a/app/Http/Requests/V1/Process/UpdateProcessRequest.php b/app/Http/Requests/V1/Process/UpdateProcessRequest.php index fd96339..3657914 100644 --- a/app/Http/Requests/V1/Process/UpdateProcessRequest.php +++ b/app/Http/Requests/V1/Process/UpdateProcessRequest.php @@ -20,8 +20,10 @@ public function rules(): array 'department' => ['nullable', 'string', 'max:100'], 'work_log_template' => ['nullable', 'string', 'max:100'], 'document_template_id' => ['nullable', 'integer', 'exists:document_templates,id'], - 'needs_work_log' => ['nullable', 'boolean'], 'work_log_template_id' => ['nullable', 'integer', 'exists:document_templates,id'], + 'options' => ['nullable', 'array'], + 'options.needs_inspection' => ['nullable', 'boolean'], + 'options.needs_work_log' => ['nullable', 'boolean'], 'required_workers' => ['nullable', 'integer', 'min:1'], 'equipment_info' => ['nullable', 'string', 'max:255'], 'work_steps' => ['nullable'], @@ -52,8 +54,10 @@ public function attributes(): array 'department' => '담당부서', 'work_log_template' => '작업일지 양식', 'document_template_id' => '중간검사 양식', - 'needs_work_log' => '작업일지 여부', 'work_log_template_id' => '작업일지 양식 ID', + 'options' => '공정 설정', + 'options.needs_inspection' => '중간검사 여부', + 'options.needs_work_log' => '작업일지 여부', 'required_workers' => '필요인원', 'equipment_info' => '설비정보', 'work_steps' => '작업단계', diff --git a/app/Models/Process.php b/app/Models/Process.php index 23df3f0..6dc1636 100644 --- a/app/Models/Process.php +++ b/app/Models/Process.php @@ -28,8 +28,8 @@ class Process extends Model 'department', 'work_log_template', 'document_template_id', - 'needs_work_log', 'work_log_template_id', + 'options', 'required_workers', 'equipment_info', 'work_steps', @@ -43,7 +43,7 @@ class Process extends Model protected $casts = [ 'work_steps' => 'array', 'is_active' => 'boolean', - 'needs_work_log' => 'boolean', + 'options' => 'array', 'required_workers' => 'integer', ]; diff --git a/database/migrations/2026_02_11_200001_add_options_to_processes.php b/database/migrations/2026_02_11_200001_add_options_to_processes.php new file mode 100644 index 0000000..9c96214 --- /dev/null +++ b/database/migrations/2026_02_11_200001_add_options_to_processes.php @@ -0,0 +1,59 @@ +json('options')->nullable()->after('work_log_template_id')->comment('공정 설정 (needs_work_log, needs_inspection 등)'); + }); + + // 2. 기존 needs_work_log 데이터를 options로 이동 + DB::table('processes')->orderBy('id')->each(function ($process) { + DB::table('processes')->where('id', $process->id)->update([ + 'options' => json_encode([ + 'needs_work_log' => (bool) $process->needs_work_log, + 'needs_inspection' => false, + ]), + ]); + }); + + // 3. needs_work_log 컬럼 제거 + Schema::table('processes', function (Blueprint $table) { + $table->dropColumn('needs_work_log'); + }); + } + + public function down(): void + { + // 1. needs_work_log 컬럼 복원 + Schema::table('processes', function (Blueprint $table) { + $table->boolean('needs_work_log')->default(false)->after('document_template_id')->comment('작업일지 여부'); + }); + + // 2. options에서 needs_work_log 데이터 복원 + DB::table('processes')->whereNotNull('options')->each(function ($process) { + $options = json_decode($process->options, true); + DB::table('processes')->where('id', $process->id)->update([ + 'needs_work_log' => $options['needs_work_log'] ?? false, + ]); + }); + + // 3. options 컬럼 제거 + Schema::table('processes', function (Blueprint $table) { + $table->dropColumn('options'); + }); + } +}; \ No newline at end of file