Files
sam-manage/app/Models/Admin/AdminApiFlow.php
hskwon ff943ab728 feat: API Flow Tester 기능 기반 구조 추가
- 모델: AdminApiFlow, AdminApiFlowRun
- 컨트롤러: FlowTesterController
- 뷰: index, create, edit, history, run-detail
- 사이드바 메뉴에 "개발 도구" 그룹 추가
- 라우트 설정
2025-11-27 19:02:18 +09:00

101 lines
2.1 KiB
PHP

<?php
namespace App\Models\Admin;
use App\Models\User;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;
/**
* API Flow Tester - 플로우 정의 모델
*
* @property int $id
* @property string $name
* @property string|null $description
* @property string|null $category
* @property array $flow_definition
* @property bool $is_active
* @property int|null $created_by
* @property int|null $updated_by
* @property \Carbon\Carbon $created_at
* @property \Carbon\Carbon $updated_at
*/
class AdminApiFlow extends Model
{
protected $table = 'admin_api_flows';
protected $fillable = [
'name',
'description',
'category',
'flow_definition',
'is_active',
'created_by',
'updated_by',
];
protected $casts = [
'flow_definition' => 'array',
'is_active' => 'boolean',
'created_by' => 'integer',
'updated_by' => 'integer',
];
/**
* 활성화된 플로우만 조회
*/
public function scopeActive($query)
{
return $query->where('is_active', true);
}
/**
* 카테고리로 필터링
*/
public function scopeCategory($query, string $category)
{
return $query->where('category', $category);
}
/**
* 관계: 실행 이력
*/
public function runs(): HasMany
{
return $this->hasMany(AdminApiFlowRun::class, 'flow_id');
}
/**
* 관계: 생성자
*/
public function creator(): BelongsTo
{
return $this->belongsTo(User::class, 'created_by');
}
/**
* 관계: 수정자
*/
public function updater(): BelongsTo
{
return $this->belongsTo(User::class, 'updated_by');
}
/**
* 최근 실행 결과 조회
*/
public function latestRun(): ?AdminApiFlowRun
{
return $this->runs()->latest('created_at')->first();
}
/**
* 플로우 정의에서 스텝 수 반환
*/
public function getStepCountAttribute(): int
{
return count($this->flow_definition['steps'] ?? []);
}
}