Files
sam-manage/app/Models/DevTools/ApiTemplate.php
hskwon bfbf4d3225 feat(api-explorer): Phase 1 기본 구조 및 OpenAPI 파싱 구현
- Config: api-explorer.php (환경, 보안, 캐시 설정)
- Migration: api_bookmarks, api_templates, api_histories, api_environments
- Model: ApiBookmark, ApiTemplate, ApiHistory, ApiEnvironment
- Service: OpenApiParserService, ApiRequestService, ApiExplorerService
- Controller: ApiExplorerController (CRUD, 실행, 히스토리)
- View: 3-Panel 레이아웃 (sidebar, request, response, history)
- Route: 23개 엔드포인트 등록

Swagger UI 대체 개발 도구, HTMX 기반 SPA 경험
2025-12-17 21:06:41 +09:00

88 lines
2.0 KiB
PHP

<?php
namespace App\Models\DevTools;
use App\Models\User;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
/**
* API 요청 템플릿 모델
*
* @property int $id
* @property int $user_id
* @property string $endpoint
* @property string $method
* @property string $name
* @property string|null $description
* @property array|null $headers
* @property array|null $path_params
* @property array|null $query_params
* @property array|null $body
* @property bool $is_shared
* @property \Illuminate\Support\Carbon|null $created_at
* @property \Illuminate\Support\Carbon|null $updated_at
*/
class ApiTemplate extends Model
{
protected $fillable = [
'user_id',
'endpoint',
'method',
'name',
'description',
'headers',
'path_params',
'query_params',
'body',
'is_shared',
];
protected $casts = [
'headers' => 'array',
'path_params' => 'array',
'query_params' => 'array',
'body' => 'array',
'is_shared' => 'boolean',
];
/**
* 사용자 관계
*/
public function user(): BelongsTo
{
return $this->belongsTo(User::class);
}
/**
* 공유된 템플릿 스코프
*/
public function scopeShared($query)
{
return $query->where('is_shared', true);
}
/**
* 특정 엔드포인트의 템플릿 스코프
*/
public function scopeForEndpoint($query, string $endpoint, string $method)
{
return $query->where('endpoint', $endpoint)->where('method', $method);
}
/**
* HTTP 메서드 배지 색상
*/
public function getMethodColorAttribute(): string
{
return match (strtoupper($this->method)) {
'GET' => 'green',
'POST' => 'blue',
'PUT' => 'yellow',
'PATCH' => 'orange',
'DELETE' => 'red',
default => 'gray',
};
}
}