uid = $userId; } /** * @NoAdminRequired * * @return JsonResponse */ #[TrapError] public function index(): JsonResponse { if ($this->uid === null) { return JsonResponse::error('User not found', Http::STATUS_UNAUTHORIZED); } $actions = $this->quickActionsService->findAll($this->uid); return JsonResponse::success($actions); } /** * @NoAdminRequired * @param string $name * * @return JsonResponse */ #[TrapError] public function create(string $name, int $accountId): JsonResponse { if ($this->uid === null) { return JsonResponse::error('User not found', Http::STATUS_UNAUTHORIZED); } try { $account = $this->accountService->findById($accountId); } catch (DoesNotExistException $e) { return JsonResponse::fail('Account not found', Http::STATUS_BAD_REQUEST); } if ($account->getUserId() !== $this->uid) { return JsonResponse::fail('Account not found', Http::STATUS_BAD_REQUEST); } try { $quickAction = $this->quickActionsService->create($name, $accountId); } catch (ServiceException $e) { return JsonResponse::fail($e->getMessage(), Http::STATUS_BAD_REQUEST); } return JsonResponse::success($quickAction, Http::STATUS_CREATED); } /** * @NoAdminRequired * @param int $id * @param string $name * * @return JsonResponse */ #[TrapError] public function update(int $id, string $name): JsonResponse { if ($this->uid === null) { return JsonResponse::error('User not found', Http::STATUS_UNAUTHORIZED); } $quickAction = $this->quickActionsService->find($id, $this->uid); if ($quickAction === null) { return JsonResponse::error('Quick action not found', Http::STATUS_NOT_FOUND); } $quickAction = $this->quickActionsService->update($quickAction, $name); return JsonResponse::success($quickAction, Http::STATUS_OK); } /** * @NoAdminRequired * * @return JsonResponse */ public function destroy(int $id): JsonResponse { if ($this->uid === null) { return JsonResponse::error('User not found', Http::STATUS_UNAUTHORIZED); } try { $this->quickActionsService->delete($id, $this->uid); return JsonResponse::success(); } catch (DoesNotExistException $e) { return JsonResponse::fail('Quick action not found', Http::STATUS_NOT_FOUND); } } }