Files
sam-api/app/Http/Resources/Api/V1/BendingItemResource.php
김보곤 ccdc28c44e fix: [bending] 절곡품 API 화이트리스트 추가 및 presignedUrl 에러 핸들링
- bending-items, guiderail-models 등 MNG→API 호출 라우트 화이트리스트 등록
- BendingItemResource에서 S3 미설정 환경 presignedUrl 에러 try-catch 처리
2026-03-21 09:40:11 +09:00

86 lines
3.1 KiB
PHP

<?php
namespace App\Http\Resources\Api\V1;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
class BendingItemResource extends JsonResource
{
public function toArray(Request $request): array
{
return [
'id' => $this->id,
'code' => $this->code,
'legacy_code' => $this->legacy_code,
// 정규 컬럼 직접 참조
'item_name' => $this->item_name,
'item_sep' => $this->item_sep,
'item_bending' => $this->item_bending,
'item_spec' => $this->item_spec,
'material' => $this->material,
'model_name' => $this->model_name,
'model_UA' => $this->model_UA,
'rail_width' => $this->rail_width ? (int) $this->rail_width : null,
// 케이스 전용
'exit_direction' => $this->exit_direction,
'front_bottom' => $this->front_bottom ? (int) $this->front_bottom : null,
'box_width' => $this->box_width ? (int) $this->box_width : null,
'box_height' => $this->box_height ? (int) $this->box_height : null,
'inspection_door' => $this->inspection_door,
// 원자재 길이
'length_code' => $this->length_code,
'length_mm' => $this->length_mm,
// 전개도 (JSON 컬럼)
'bendingData' => $this->bending_data,
// 비정형 속성 (options)
'search_keyword' => $this->getOption('search_keyword'),
'author' => $this->getOption('author'),
'memo' => $this->getOption('memo'),
'registration_date' => $this->getOption('registration_date'),
// 이미지
'image_file_id' => $this->getImageFileId(),
'image_url' => $this->getImageUrl(),
// 추적
'legacy_bending_id' => $this->legacy_bending_id,
'legacy_bending_num' => $this->legacy_bending_id, // MNG2 호환
'modified_by' => $this->getOption('modified_by'),
// MNG2 호환 (items 기반 필드명)
'name' => $this->item_name,
'front_bottom_width' => $this->front_bottom ? (int) $this->front_bottom : null,
'item_type' => 'PT',
'item_category' => 'BENDING',
'unit' => 'EA',
// 계산값
'width_sum' => $this->width_sum,
'bend_count' => $this->bend_count,
// 메타
'is_active' => $this->is_active,
'created_at' => $this->created_at?->format('Y-m-d H:i:s'),
'updated_at' => $this->updated_at?->format('Y-m-d H:i:s'),
];
}
private function getImageFile(): ?\App\Models\Commons\File
{
return $this->files()
->where('field_key', 'bending_diagram')
->orderByDesc('id')
->first();
}
private function getImageFileId(): ?int
{
return $this->getImageFile()?->id;
}
private function getImageUrl(): ?string
{
try {
return $this->getImageFile()?->presignedUrl();
} catch (\Throwable) {
return null;
}
}
}