- ArchivedRecordService: batch_id 기준 그룹핑 쿼리 추가 - Controller: batchId 파라미터로 상세 조회 변경 - 목록: 작업 설명, 레코드 타입, 레코드 수 표시 - 상세: batch 내 모든 레코드를 카드 형태로 표시 - 한번의 삭제 작업이 하나의 행으로 표시됨
88 lines
2.4 KiB
PHP
88 lines
2.4 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
|
|
) {}
|
|
|
|
/**
|
|
* 아카이브 레코드 목록 조회 (batch 그룹핑)
|
|
*/
|
|
public function index(Request $request): JsonResponse
|
|
{
|
|
$records = $this->archivedRecordService->getArchivedRecordsBatched(
|
|
$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(),
|
|
],
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* 특정 batch의 레코드 조회
|
|
*/
|
|
public function show(Request $request, string $batchId): JsonResponse
|
|
{
|
|
$records = $this->archivedRecordService->getRecordsByBatchId($batchId);
|
|
|
|
if ($records->isEmpty()) {
|
|
return response()->json([
|
|
'success' => false,
|
|
'message' => '아카이브 레코드를 찾을 수 없습니다.',
|
|
], 404);
|
|
}
|
|
|
|
// HTMX 요청 시 HTML 반환
|
|
if ($request->header('HX-Request')) {
|
|
return response()->json([
|
|
'html' => view('archived-records.partials.detail', compact('records'))->render(),
|
|
]);
|
|
}
|
|
|
|
return response()->json([
|
|
'success' => true,
|
|
'data' => $records,
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* 아카이브 통계
|
|
*/
|
|
public function stats(Request $request): JsonResponse
|
|
{
|
|
$stats = $this->archivedRecordService->getStats();
|
|
|
|
return response()->json([
|
|
'success' => true,
|
|
'data' => $stats,
|
|
]);
|
|
}
|
|
}
|