From 073ad11ecdc6df97d72dc38fbd6b825d483f1e28 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B6=8C=ED=98=81=EC=84=B1?= Date: Thu, 12 Mar 2026 01:45:53 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20[QMS]=20=EC=A0=90=EA=B2=80=ED=91=9C=20?= =?UTF-8?q?=ED=86=A0=EA=B8=80=20=ED=95=B4=EC=A0=9C=20=EC=95=88=EB=90=98?= =?UTF-8?q?=EB=8A=94=20=EB=B2=84=EA=B7=B8=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - PHP foreach 참조(&)와 ?? 연산자 조합 시 임시 복사본이 생성되어 원본 배열 수정 불가 - `$category['subItems'] ?? []` → `empty() + continue` + `$category['subItems']` 로 변경 - 토글 API가 항상 is_completed: true 반환하던 문제 해결 Co-Authored-By: Claude Opus 4.6 --- app/Services/ChecklistTemplateService.php | 48 +++++++++++++++++++++-- 1 file changed, 45 insertions(+), 3 deletions(-) diff --git a/app/Services/ChecklistTemplateService.php b/app/Services/ChecklistTemplateService.php index a0ca96e..018928f 100644 --- a/app/Services/ChecklistTemplateService.php +++ b/app/Services/ChecklistTemplateService.php @@ -93,17 +93,59 @@ public function save(int $id, array $data): array $template->refresh(); $this->auditLogger->log( + $this->tenantId(), self::AUDIT_TARGET, $template->id, 'updated', $before, - $template->toArray(), - $this->apiUserId() + $template->toArray() ); return $this->getByType($template->type); } + /** + * 항목 완료 토글 + */ + public function toggleItem(int $id, string $subItemId): array + { + $template = ChecklistTemplate::findOrFail($id); + $categories = $template->categories; + $toggled = null; + + foreach ($categories as &$category) { + if (empty($category['subItems'])) { + continue; + } + foreach ($category['subItems'] as &$subItem) { + if ($subItem['id'] === $subItemId) { + $subItem['is_completed'] = ! ($subItem['is_completed'] ?? false); + $subItem['completed_at'] = $subItem['is_completed'] ? now()->toIso8601String() : null; + $toggled = $subItem; + break 2; + } + } + unset($subItem); + } + unset($category); + + if (! $toggled) { + throw new NotFoundHttpException(__('error.not_found')); + } + + $template->update([ + 'categories' => $categories, + 'updated_by' => $this->apiUserId(), + ]); + + return [ + 'id' => $toggled['id'], + 'name' => $toggled['name'], + 'is_completed' => $toggled['is_completed'], + 'completed_at' => $toggled['completed_at'], + ]; + } + /** * 항목별 파일 목록 조회 */ @@ -152,7 +194,7 @@ public function uploadDocument(int $templateId, string $subItemId, $uploadedFile ); // 파일 저장 - Storage::disk('tenant')->put($filePath, file_get_contents($uploadedFile->getPathname())); + Storage::disk('r2')->put($filePath, file_get_contents($uploadedFile->getPathname())); // DB 레코드 생성 $file = File::create([