- ArchivedRecord, ArchivedRecordRelation 모델 추가 - ArchivedRecordService 추가 (읽기 전용) - 목록/상세 컨트롤러 및 뷰 구현 - HTMX 기반 테이블 필터링 및 페이지네이션 - 사이드바 메뉴 연결
88 lines
2.3 KiB
PHP
88 lines
2.3 KiB
PHP
<?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
|
|
) {}
|
|
|
|
/**
|
|
* 아카이브 레코드 목록 조회
|
|
*/
|
|
public function index(Request $request): JsonResponse
|
|
{
|
|
$records = $this->archivedRecordService->getArchivedRecords(
|
|
$request->all(),
|
|
$request->integer('per_page', 15)
|
|
);
|
|
|
|
// HTMX 요청 시 HTML 반환
|
|
if ($request->header('HX-Request')) {
|
|
$html = view('archived-records.partials.table', compact('records'))->render();
|
|
|
|
return response()->json([
|
|
'html' => $html,
|
|
]);
|
|
}
|
|
|
|
// 일반 요청 시 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(),
|
|
],
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* 특정 아카이브 레코드 조회
|
|
*/
|
|
public function show(Request $request, int $id): JsonResponse
|
|
{
|
|
$record = $this->archivedRecordService->getArchivedRecordById($id);
|
|
|
|
if (! $record) {
|
|
return response()->json([
|
|
'success' => false,
|
|
'message' => '아카이브 레코드를 찾을 수 없습니다.',
|
|
], 404);
|
|
}
|
|
|
|
// HTMX 요청 시 HTML 반환
|
|
if ($request->header('HX-Request')) {
|
|
return response()->json([
|
|
'html' => view('archived-records.partials.detail', compact('record'))->render(),
|
|
]);
|
|
}
|
|
|
|
return response()->json([
|
|
'success' => true,
|
|
'data' => $record,
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* 아카이브 통계
|
|
*/
|
|
public function stats(Request $request): JsonResponse
|
|
{
|
|
$stats = $this->archivedRecordService->getStats();
|
|
|
|
return response()->json([
|
|
'success' => true,
|
|
'data' => $stats,
|
|
]);
|
|
}
|
|
}
|