- GuiderailModelController/Service/Resource: 가이드레일/케이스/하단마감재 통합 CRUD - item_category 필터 (GUIDERAIL_MODEL/SHUTTERBOX_MODEL/BOTTOMBAR_MODEL) - BendingItemResource: legacy_bending_num 노출 추가 - ApiKeyMiddleware: guiderail-models, files 화이트리스트 추가 - Swagger: BendingItemApi, GuiderailModelApi 문서 (케이스/하단마감재 필드 포함) - 마이그레이션 커맨드 5개: GuiderailImportLegacy, BendingProductImportLegacy, BendingImportImages, BendingModelImportImages, BendingModelImportAssemblyImages - 데이터: GR 20건 + SB 30건 + BB 10건 + 이미지 473건 R2 업로드
73 lines
2.7 KiB
PHP
73 lines
2.7 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,
|
|
'name' => $this->name,
|
|
'item_type' => $this->item_type,
|
|
'item_category' => $this->item_category,
|
|
'unit' => $this->unit,
|
|
'is_active' => $this->is_active,
|
|
// options → 최상위로 노출
|
|
'item_name' => $this->getOption('item_name'),
|
|
'item_sep' => $this->getOption('item_sep'),
|
|
'item_bending' => $this->getOption('item_bending'),
|
|
'item_spec' => $this->getOption('item_spec'),
|
|
'material' => $this->getOption('material'),
|
|
'model_name' => $this->getOption('model_name'),
|
|
'model_UA' => $this->getOption('model_UA'),
|
|
'search_keyword' => $this->getOption('search_keyword'),
|
|
'rail_width' => $this->getOption('rail_width'),
|
|
'registration_date' => $this->getOption('registration_date'),
|
|
'author' => $this->getOption('author'),
|
|
'memo' => $this->getOption('memo'),
|
|
// 케이스 전용
|
|
'exit_direction' => $this->getOption('exit_direction'),
|
|
'front_bottom_width' => $this->getOption('front_bottom_width'),
|
|
'box_width' => $this->getOption('box_width'),
|
|
'box_height' => $this->getOption('box_height'),
|
|
// 전개도
|
|
'bendingData' => $this->getOption('bendingData'),
|
|
// PREFIX 관련
|
|
'prefix' => $this->getOption('prefix'),
|
|
'length_code' => $this->getOption('length_code'),
|
|
'length_mm' => $this->getOption('length_mm'),
|
|
// 추적
|
|
'legacy_bending_num' => $this->getOption('legacy_bending_num'),
|
|
// 계산값
|
|
'width_sum' => $this->getWidthSum(),
|
|
'bend_count' => $this->getBendCount(),
|
|
// 메타
|
|
'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 getWidthSum(): ?int
|
|
{
|
|
$data = $this->getOption('bendingData', []);
|
|
if (empty($data)) {
|
|
return null;
|
|
}
|
|
$last = end($data);
|
|
|
|
return isset($last['sum']) ? (int) $last['sum'] : null;
|
|
}
|
|
|
|
private function getBendCount(): int
|
|
{
|
|
$data = $this->getOption('bendingData', []);
|
|
|
|
return count(array_filter($data, fn ($d) => ($d['rate'] ?? '') !== ''));
|
|
}
|
|
}
|