update controllers logic

This commit is contained in:
root
2026-04-23 00:04:35 -04:00
parent 1977a513df
commit ca4ba272fc
353 changed files with 13402 additions and 1301 deletions
+18 -5
View File
@@ -2,7 +2,7 @@
namespace App\Http\Controllers\Api\Ui;
use App\Http\Controllers\Api\BaseApiController;
use App\Http\Controllers\Api\Core\BaseApiController;
use App\Http\Requests\Ui\UiStyleRequest;
use App\Http\Resources\Ui\UiStyleResource;
use App\Services\Ui\UiStyleService;
@@ -18,15 +18,28 @@ class UiController extends BaseApiController
public function style(UiStyleRequest $request): JsonResponse
{
$userId = (int) (auth()->id() ?? 0);
if ($userId <= 0) {
return $this->error('Unauthorized.', Response::HTTP_UNAUTHORIZED);
$guard = $this->authenticatedUserIdOrUnauthorized();
if ($guard instanceof JsonResponse) {
return $guard;
}
$prefs = $this->styleService->update($userId, $request->validated());
$prefs = $this->styleService->update($guard, $request->validated());
return $this->success([
'preferences' => new UiStyleResource($prefs),
], 'Style updated.');
}
/**
* @return int|JsonResponse
*/
private function authenticatedUserIdOrUnauthorized(): int|JsonResponse
{
$userId = (int) (auth()->id() ?? 0);
if ($userId <= 0) {
return $this->error('Unauthorized.', Response::HTTP_UNAUTHORIZED);
}
return $userId;
}
}