refactor:用 AdminApiList 统一后台列表类接口的响应格式

This commit is contained in:
2026-05-13 11:36:24 +08:00
parent edd863764b
commit 5d2dbdbe1d
29 changed files with 622 additions and 293 deletions

View File

@@ -4,7 +4,7 @@ namespace App\Http\Controllers\Api\V1\Admin\Audit;
use App\Http\Controllers\Controller;
use App\Models\AuditLog;
use App\Support\ApiResponse;
use App\Support\AdminApiList;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
@@ -15,8 +15,7 @@ final class AuditLogIndexController extends Controller
{
public function __invoke(Request $request): JsonResponse
{
$perPage = min(max((int) $request->integer('per_page', 25), 1), 100);
$page = max((int) $request->integer('page', 1), 1);
$p = AdminApiList::readPaging($request);
$module = trim((string) $request->query('module_code', ''));
$action = trim((string) $request->query('action_code', ''));
$operatorType = trim((string) $request->query('operator_type', ''));
@@ -33,17 +32,9 @@ final class AuditLogIndexController extends Controller
$q->where('operator_type', $operatorType);
}
$paginator = $q->paginate($perPage, ['*'], 'page', $page);
$paginator = $q->paginate($p['perPage'], ['*'], 'page', $p['page']);
return ApiResponse::success([
'items' => collect($paginator->items())->map(fn (AuditLog $r) => $this->row($r))->all(),
'meta' => [
'current_page' => $paginator->currentPage(),
'per_page' => $paginator->perPage(),
'total' => $paginator->total(),
'last_page' => $paginator->lastPage(),
],
]);
return AdminApiList::json($paginator, fn (AuditLog $r) => $this->row($r));
}
/** @return array<string, mixed> */