- BendingItemController: CRUD + filters 엔드포인트 (pagination 메타 보존) - BendingItemService: items 테이블 item_category=BENDING 필터 기반 - BendingItemResource: options → 최상위 필드 노출 + 계산값(width_sum, bend_count) - FormRequest: Index/Store/Update 유효성 검증 (unique:items,code 포함) - BendingFillOptions: BD-* prefix/분류 속성 자동 보강 커맨드 - BendingImportLegacy: chandj 레거시 전개도(bendingData) 임포트 커맨드 (125/170건 매칭) - ensureContext: Bearer 토큰 없이 X-TENANT-ID 헤더로 컨텍스트 설정
71 lines
2.6 KiB
PHP
71 lines
2.6 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'),
|
|
// 계산값
|
|
'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'] ?? '') !== ''));
|
|
}
|
|
}
|