Fix docs drift and unify avatar API error envelope
This commit is contained in:
@@ -21,10 +21,7 @@ if ($method === 'GET') {
|
||||
|
||||
$path = $userAvatarService->findAvatarPath($uuid, $size);
|
||||
if (!$path || !is_file($path)) {
|
||||
http_response_code(404);
|
||||
header('Content-Type: application/json');
|
||||
echo json_encode(['error' => 'not_found']);
|
||||
return;
|
||||
ApiResponse::notFound();
|
||||
}
|
||||
|
||||
$mime = $userAvatarService->detectMime($path);
|
||||
|
||||
@@ -14,28 +14,19 @@ $request = requestInput();
|
||||
|
||||
$uuid = trim((string) ($id ?? ''));
|
||||
if ($uuid === '') {
|
||||
http_response_code(404);
|
||||
header('Content-Type: application/json');
|
||||
echo json_encode(['error' => 'not_found']);
|
||||
return;
|
||||
ApiResponse::notFound();
|
||||
}
|
||||
|
||||
$tenantAvatarService = (app(TenantServicesFactory::class))->createTenantAvatarService();
|
||||
|
||||
if (!$tenantAvatarService->isValidUuid($uuid)) {
|
||||
http_response_code(404);
|
||||
header('Content-Type: application/json');
|
||||
echo json_encode(['error' => 'not_found']);
|
||||
return;
|
||||
ApiResponse::notFound();
|
||||
}
|
||||
|
||||
$tenant = app(\MintyPHP\Service\Directory\DirectoryServicesFactory::class)->createTenantService()->findByUuid($uuid);
|
||||
$tenantId = (int) ($tenant['id'] ?? 0);
|
||||
if ($tenantId <= 0) {
|
||||
http_response_code(404);
|
||||
header('Content-Type: application/json');
|
||||
echo json_encode(['error' => 'not_found']);
|
||||
return;
|
||||
ApiResponse::notFound();
|
||||
}
|
||||
|
||||
ApiAuth::requireResourceAccess('tenants', $tenantId);
|
||||
@@ -43,10 +34,7 @@ ApiAuth::requireResourceAccess('tenants', $tenantId);
|
||||
$size = $request->hasQuery('size') ? $request->queryInt('size') : null;
|
||||
$path = $tenantAvatarService->findAvatarPath($uuid, $size);
|
||||
if (!$path || !is_file($path)) {
|
||||
http_response_code(404);
|
||||
header('Content-Type: application/json');
|
||||
echo json_encode(['error' => 'not_found']);
|
||||
return;
|
||||
ApiResponse::notFound();
|
||||
}
|
||||
|
||||
$mime = $tenantAvatarService->detectMime($path);
|
||||
|
||||
@@ -15,10 +15,7 @@ $request = requestInput();
|
||||
|
||||
$uuid = trim((string) ($id ?? ''));
|
||||
if ($uuid === '') {
|
||||
http_response_code(404);
|
||||
header('Content-Type: application/json');
|
||||
echo json_encode(['error' => 'not_found']);
|
||||
return;
|
||||
ApiResponse::notFound();
|
||||
}
|
||||
|
||||
$userAccountService = app(UserAccountService::class);
|
||||
@@ -36,26 +33,27 @@ $decision = $authorizationService->authorize(UserAuthorizationPolicy::ABILITY_AP
|
||||
|
||||
if (!$decision->isAllowed()) {
|
||||
$status = $decision->status() ?: 403;
|
||||
http_response_code($status);
|
||||
header('Content-Type: application/json');
|
||||
echo json_encode(['error' => $decision->error() ?: 'forbidden']);
|
||||
return;
|
||||
$error = $decision->error() ?: 'forbidden';
|
||||
|
||||
if ($status === 404) {
|
||||
ApiResponse::notFound($error);
|
||||
}
|
||||
|
||||
if ($status === 403) {
|
||||
ApiResponse::forbidden($error);
|
||||
}
|
||||
|
||||
ApiResponse::error($error, $status);
|
||||
}
|
||||
|
||||
if (!$user) {
|
||||
http_response_code(404);
|
||||
header('Content-Type: application/json');
|
||||
echo json_encode(['error' => 'not_found']);
|
||||
return;
|
||||
ApiResponse::notFound();
|
||||
}
|
||||
|
||||
$size = $request->hasQuery('size') ? $request->queryInt('size') : null;
|
||||
$path = $userAvatarService->findAvatarPath($uuid, $size);
|
||||
if (!$path || !is_file($path)) {
|
||||
http_response_code(404);
|
||||
header('Content-Type: application/json');
|
||||
echo json_encode(['error' => 'not_found']);
|
||||
return;
|
||||
ApiResponse::notFound();
|
||||
}
|
||||
|
||||
$mime = $userAvatarService->detectMime($path);
|
||||
|
||||
Reference in New Issue
Block a user