From 917b75d4b46d288737d088e4bbf1f780442969c1 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:42:13 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20[bending]=20=EA=B0=80=EC=9D=B4=EB=93=9C?= =?UTF-8?q?=EB=A0=88=EC=9D=BC/=EC=BC=80=EC=9D=B4=EC=8A=A4=20=EB=B6=80?= =?UTF-8?q?=ED=92=88=20=EC=A1=B0=ED=95=A9=EC=97=90=20=EA=B8=B0=EC=B4=88?= =?UTF-8?q?=EC=9E=90=EB=A3=8C=20=ED=92=88=EB=AA=A9=EC=BD=94=EB=93=9C(item?= =?UTF-8?q?=5Fcode)=20=EB=A7=A4=ED=95=91=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Api/V1/GuiderailModelResource.php | 36 ++++++++++++------- 1 file changed, 23 insertions(+), 13 deletions(-) diff --git a/app/Http/Resources/Api/V1/GuiderailModelResource.php b/app/Http/Resources/Api/V1/GuiderailModelResource.php index ba94ab04..415fe099 100644 --- a/app/Http/Resources/Api/V1/GuiderailModelResource.php +++ b/app/Http/Resources/Api/V1/GuiderailModelResource.php @@ -50,7 +50,7 @@ public function toArray(Request $request): array 'image_file_id' => $this->getImageFileId(), 'image_url' => $this->getImageUrl(), // 부품 조합 - 'components' => $this->enrichComponentsWithImageUrls($components), + 'components' => $this->enrichComponents($components), 'material_summary' => $materialSummary, 'component_count' => count($components), // 메타 @@ -88,23 +88,32 @@ private function getImageUrl(): ?string return $this->getImageFile()?->presignedUrl(); } - private function enrichComponentsWithImageUrls(array $components): array + private function enrichComponents(array $components): array { - $fileIds = array_filter(array_column($components, 'image_file_id')); - if (empty($fileIds)) { - return $components; - } + // sam_item_id → 기초자료 품목코드 매핑 + $itemIds = array_filter(array_column($components, 'sam_item_id')); + $itemCodes = ! empty($itemIds) + ? \App\Models\BendingItem::withoutGlobalScopes()->whereIn('id', $itemIds)->pluck('code', 'id')->toArray() + : []; - $files = \App\Models\Commons\File::whereIn('id', $fileIds) - ->whereNull('deleted_at') - ->get() - ->keyBy('id'); + // image_file_id → presigned URL 매핑 + $fileIds = array_filter(array_column($components, 'image_file_id')); + $files = ! empty($fileIds) + ? \App\Models\Commons\File::whereIn('id', $fileIds)->whereNull('deleted_at')->get()->keyBy('id') + : collect(); foreach ($components as &$comp) { + $samId = $comp['sam_item_id'] ?? null; + $comp['item_code'] = $samId ? ($itemCodes[$samId] ?? null) : null; + $fileId = $comp['image_file_id'] ?? null; - $comp['image_url'] = $fileId && isset($files[$fileId]) - ? $files[$fileId]->presignedUrl() - : null; + try { + $comp['image_url'] = $fileId && $files->has($fileId) + ? $files[$fileId]->presignedUrl() + : null; + } catch (\Throwable) { + $comp['image_url'] = null; + } } unset($comp); @@ -122,6 +131,7 @@ private function calcMaterialSummary(array $components): array $summary[$material] = ($summary[$material] ?? 0) + ($widthSum * $qty); } } + return $summary; } }