feat: API 사용 현황 및 폐기 후보 관리 기능 추가
- API 사용 통계 조회 및 미사용 API 식별 기능 - 폐기 후보 등록/상태변경/삭제 기능 - API Explorer에서 사용 현황 페이지 링크 추가 - 북마크 토글 버그 수정 (라우트-컨트롤러 메서드명 일치)
This commit is contained in:
@@ -5,6 +5,7 @@
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Services\ApiExplorer\ApiExplorerService;
|
||||
use App\Services\ApiExplorer\ApiRequestService;
|
||||
use App\Services\ApiExplorer\ApiUsageService;
|
||||
use App\Services\ApiExplorer\OpenApiParserService;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
@@ -18,7 +19,8 @@ class ApiExplorerController extends Controller
|
||||
public function __construct(
|
||||
private OpenApiParserService $parser,
|
||||
private ApiRequestService $requester,
|
||||
private ApiExplorerService $explorer
|
||||
private ApiExplorerService $explorer,
|
||||
private ApiUsageService $usageService
|
||||
) {}
|
||||
|
||||
/*
|
||||
@@ -199,9 +201,28 @@ public function bookmarks(): View
|
||||
}
|
||||
|
||||
/**
|
||||
* 즐겨찾기 추가/토글
|
||||
* 즐겨찾기 저장
|
||||
*/
|
||||
public function addBookmark(Request $request): JsonResponse
|
||||
public function storeBookmark(Request $request): JsonResponse
|
||||
{
|
||||
$validated = $request->validate([
|
||||
'endpoint' => 'required|string|max:500',
|
||||
'method' => 'required|string|max:10',
|
||||
'display_name' => 'nullable|string|max:100',
|
||||
]);
|
||||
|
||||
$bookmark = $this->explorer->addBookmark(auth()->id(), $validated);
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'bookmark' => $bookmark,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 즐겨찾기 토글
|
||||
*/
|
||||
public function toggleBookmark(Request $request): JsonResponse
|
||||
{
|
||||
$validated = $request->validate([
|
||||
'endpoint' => 'required|string|max:500',
|
||||
@@ -439,4 +460,182 @@ public function users(): JsonResponse
|
||||
|
||||
return response()->json($users);
|
||||
}
|
||||
|
||||
/**
|
||||
* 즐겨찾기 수정
|
||||
*/
|
||||
public function updateBookmark(Request $request, int $id): JsonResponse
|
||||
{
|
||||
$validated = $request->validate([
|
||||
'display_name' => 'nullable|string|max:100',
|
||||
]);
|
||||
|
||||
$bookmark = $this->explorer->updateBookmark($id, $validated);
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'bookmark' => $bookmark,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 즐겨찾기 삭제
|
||||
*/
|
||||
public function deleteBookmark(int $id): JsonResponse
|
||||
{
|
||||
$this->explorer->removeBookmark($id);
|
||||
|
||||
return response()->json(['success' => true]);
|
||||
}
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| API Usage & Deprecation
|
||||
|--------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
/**
|
||||
* API 사용 현황 페이지
|
||||
*/
|
||||
public function usage(): View
|
||||
{
|
||||
$comparison = $this->usageService->getApiUsageComparison();
|
||||
$deprecations = $this->usageService->getDeprecations();
|
||||
$dailyTrend = $this->usageService->getDailyTrend(30);
|
||||
|
||||
return view('dev-tools.api-explorer.usage', compact(
|
||||
'comparison',
|
||||
'deprecations',
|
||||
'dailyTrend'
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* API 사용 통계 조회 (JSON)
|
||||
*/
|
||||
public function usageStats(): JsonResponse
|
||||
{
|
||||
$comparison = $this->usageService->getApiUsageComparison();
|
||||
|
||||
return response()->json($comparison);
|
||||
}
|
||||
|
||||
/**
|
||||
* 폐기 후보 목록 조회
|
||||
*/
|
||||
public function deprecations(Request $request): JsonResponse
|
||||
{
|
||||
$status = $request->input('status');
|
||||
$deprecations = $this->usageService->getDeprecations($status);
|
||||
|
||||
return response()->json($deprecations);
|
||||
}
|
||||
|
||||
/**
|
||||
* 폐기 후보 추가
|
||||
*/
|
||||
public function addDeprecation(Request $request): JsonResponse
|
||||
{
|
||||
$validated = $request->validate([
|
||||
'endpoint' => 'required|string|max:500',
|
||||
'method' => 'required|string|max:10',
|
||||
'reason' => 'nullable|string',
|
||||
]);
|
||||
|
||||
$deprecation = $this->usageService->addDeprecationCandidate(
|
||||
$validated['endpoint'],
|
||||
$validated['method'],
|
||||
$validated['reason'] ?? null,
|
||||
auth()->id()
|
||||
);
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'deprecation' => $deprecation,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 미사용 API 전체를 폐기 후보로 추가
|
||||
*/
|
||||
public function addAllUnusedAsDeprecation(): JsonResponse
|
||||
{
|
||||
$count = $this->usageService->addAllUnusedAsCandidate(auth()->id());
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'added_count' => $count,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 폐기 상태 변경
|
||||
*/
|
||||
public function updateDeprecation(Request $request, int $id): JsonResponse
|
||||
{
|
||||
$validated = $request->validate([
|
||||
'status' => 'required|string|in:candidate,scheduled,deprecated,removed',
|
||||
'reason' => 'nullable|string',
|
||||
'scheduled_date' => 'nullable|date',
|
||||
]);
|
||||
|
||||
$scheduledDate = ! empty($validated['scheduled_date'])
|
||||
? new \DateTime($validated['scheduled_date'])
|
||||
: null;
|
||||
|
||||
$deprecation = $this->usageService->updateDeprecationStatus(
|
||||
$id,
|
||||
$validated['status'],
|
||||
$validated['reason'] ?? null,
|
||||
$scheduledDate
|
||||
);
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'deprecation' => $deprecation,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 폐기 후보 삭제
|
||||
*/
|
||||
public function removeDeprecation(int $id): JsonResponse
|
||||
{
|
||||
$this->usageService->removeDeprecation($id);
|
||||
|
||||
return response()->json(['success' => true]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 일별 API 호출 추이
|
||||
*/
|
||||
public function dailyTrend(Request $request): JsonResponse
|
||||
{
|
||||
$days = $request->input('days', 30);
|
||||
$trend = $this->usageService->getDailyTrend($days);
|
||||
|
||||
return response()->json($trend);
|
||||
}
|
||||
|
||||
/**
|
||||
* 인기 API 목록
|
||||
*/
|
||||
public function popularApis(Request $request): JsonResponse
|
||||
{
|
||||
$limit = $request->input('limit', 20);
|
||||
$popular = $this->usageService->getPopularApis($limit);
|
||||
|
||||
return response()->json($popular);
|
||||
}
|
||||
|
||||
/**
|
||||
* 오래된 API 목록 (N일 이상 미사용)
|
||||
*/
|
||||
public function staleApis(Request $request): JsonResponse
|
||||
{
|
||||
$days = $request->input('days', 30);
|
||||
$stale = $this->usageService->getStaleApis($days);
|
||||
|
||||
return response()->json($stale);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user