This commit is contained in:
2023-04-21 07:11:00 +10:00
parent 5ae6e02ce8
commit 7a2f263061
29 changed files with 775 additions and 387 deletions

View File

@@ -137,6 +137,7 @@ class ApiController extends Controller
protected function respondAsResource(
mixed $data,
array $options = [],
$validationFn = null
) {
$isCollection = $options['isCollection'] ?? false;
$appendData = $options['appendData'] ?? null;
@@ -144,7 +145,14 @@ class ApiController extends Controller
$respondCode = ($options['respondCode'] ?? HttpResponseCodes::HTTP_OK);
if ($data === null || ($data instanceof Collection && $data->count() === 0)) {
return $this->respondNotFound();
$validationData = [];
if (array_key_exists('appendData', $options) === true) {
$validationData = $options['appendData'];
}
if ($validationFn === null || $validationFn($validationData) === true) {
return $this->respondNotFound();
}
}
if (is_null($resourceName) === true || empty($resourceName) === true) {

View File

@@ -35,7 +35,10 @@ class MediaController extends ApiController
$collection,
['isCollection' => true,
'appendData' => ['total' => $total]
]
],
function ($options) {
return $options['total'] === 0;
}
);
}