- File 모델에 presignedUrl() 메서드 추가 - GuiderailModelResource: image_url + components[].image_url 반환 - BendingItemResource: image_url 반환 - 소비자(MNG, React)가 별도 처리 없이 R2 직접 로드 가능
82 lines
3.0 KiB
PHP
82 lines
3.0 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
|
|
{
|
|
return $this->getImageFile()?->presignedUrl();
|
|
}
|
|
}
|