2025-11-26 22:23:37 +09:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Http\Controllers\Api\Admin;
|
|
|
|
|
|
|
|
|
|
use App\Http\Controllers\Controller;
|
|
|
|
|
use App\Services\ArchivedRecordService;
|
|
|
|
|
use Illuminate\Http\JsonResponse;
|
|
|
|
|
use Illuminate\Http\Request;
|
|
|
|
|
|
|
|
|
|
class ArchivedRecordController extends Controller
|
|
|
|
|
{
|
|
|
|
|
public function __construct(
|
|
|
|
|
private readonly ArchivedRecordService $archivedRecordService
|
|
|
|
|
) {}
|
|
|
|
|
|
|
|
|
|
/**
|
2025-11-26 23:16:39 +09:00
|
|
|
* 아카이브 레코드 목록 조회 (batch 그룹핑)
|
2025-11-26 22:23:37 +09:00
|
|
|
*/
|
2025-11-30 21:05:13 +09:00
|
|
|
public function index(Request $request): JsonResponse|\Illuminate\Http\Response
|
2025-11-26 22:23:37 +09:00
|
|
|
{
|
2025-11-26 23:16:39 +09:00
|
|
|
$records = $this->archivedRecordService->getArchivedRecordsBatched(
|
2025-11-26 22:23:37 +09:00
|
|
|
$request->all(),
|
|
|
|
|
$request->integer('per_page', 15)
|
|
|
|
|
);
|
|
|
|
|
|
2025-11-30 21:05:13 +09:00
|
|
|
// HTMX 요청 시 HTML 직접 반환
|
2025-11-26 22:23:37 +09:00
|
|
|
if ($request->header('HX-Request')) {
|
|
|
|
|
$html = view('archived-records.partials.table', compact('records'))->render();
|
|
|
|
|
|
2025-11-30 21:05:13 +09:00
|
|
|
return response($html)->header('Content-Type', 'text/html');
|
2025-11-26 22:23:37 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 일반 요청 시 JSON 반환
|
|
|
|
|
return response()->json([
|
|
|
|
|
'success' => true,
|
|
|
|
|
'data' => $records->items(),
|
|
|
|
|
'meta' => [
|
|
|
|
|
'current_page' => $records->currentPage(),
|
|
|
|
|
'last_page' => $records->lastPage(),
|
|
|
|
|
'per_page' => $records->perPage(),
|
|
|
|
|
'total' => $records->total(),
|
|
|
|
|
],
|
|
|
|
|
]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2025-11-26 23:16:39 +09:00
|
|
|
* 특정 batch의 레코드 조회
|
2025-11-26 22:23:37 +09:00
|
|
|
*/
|
2025-11-26 23:16:39 +09:00
|
|
|
public function show(Request $request, string $batchId): JsonResponse
|
2025-11-26 22:23:37 +09:00
|
|
|
{
|
2025-11-26 23:16:39 +09:00
|
|
|
$records = $this->archivedRecordService->getRecordsByBatchId($batchId);
|
2025-11-26 22:23:37 +09:00
|
|
|
|
2025-11-26 23:16:39 +09:00
|
|
|
if ($records->isEmpty()) {
|
2025-11-26 22:23:37 +09:00
|
|
|
return response()->json([
|
|
|
|
|
'success' => false,
|
|
|
|
|
'message' => '아카이브 레코드를 찾을 수 없습니다.',
|
|
|
|
|
], 404);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// HTMX 요청 시 HTML 반환
|
|
|
|
|
if ($request->header('HX-Request')) {
|
|
|
|
|
return response()->json([
|
2025-11-26 23:16:39 +09:00
|
|
|
'html' => view('archived-records.partials.detail', compact('records'))->render(),
|
2025-11-26 22:23:37 +09:00
|
|
|
]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return response()->json([
|
|
|
|
|
'success' => true,
|
2025-11-26 23:16:39 +09:00
|
|
|
'data' => $records,
|
2025-11-26 22:23:37 +09:00
|
|
|
]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 아카이브 통계
|
|
|
|
|
*/
|
|
|
|
|
public function stats(Request $request): JsonResponse
|
|
|
|
|
{
|
|
|
|
|
$stats = $this->archivedRecordService->getStats();
|
|
|
|
|
|
|
|
|
|
return response()->json([
|
|
|
|
|
'success' => true,
|
|
|
|
|
'data' => $stats,
|
|
|
|
|
]);
|
|
|
|
|
}
|
|
|
|
|
}
|