From 01d63a7f76d7348e547c3e336da329504b56bdd3 Mon Sep 17 00:00:00 2001 From: Jonathan Treffler Date: Tue, 19 Nov 2024 19:56:15 +0100 Subject: [PATCH] Added organization controller --- appinfo/routes.php | 5 ++ lib/Controller/OrganizationController.php | 61 +++++++++++++++++++++++ 2 files changed, 66 insertions(+) create mode 100644 lib/Controller/OrganizationController.php diff --git a/appinfo/routes.php b/appinfo/routes.php index b47b072..c6be018 100644 --- a/appinfo/routes.php +++ b/appinfo/routes.php @@ -8,5 +8,10 @@ return [ ['name' => 'resource#show', 'url' => '/resources/{resourceId}', 'verb' => 'GET'], ['name' => 'resource#create', 'url' => '/resources/{resourceId}', 'verb' => 'POST'], ['name' => 'resource#update', 'url' => '/resources/{resourceId}', 'verb' => 'PUT'], + ['name' => 'organization#getOrganizationProviders', 'url' => '/organizationProviders', 'verb' => 'GET'], + ['name' => 'organization#getOrganization', 'url' => '/organizationProviders/{organizationProviderId}/organizations/{organizationId}', 'verb' => 'GET'], + ['name' => 'organization#getSubOrganizations', 'url' => '/organizationProviders/{organizationProviderId}/organizations/{parentOrganizationId}/subOrganizations', 'verb' => 'GET'], + ['name' => 'organization#getTopLevelOrganizations', 'url' => '/organizationProviders/{organizationProviderId}/subOrganizations', 'verb' => 'GET'], + ['name' => 'organization#getRoles', 'url' => '/organizationProviders/{organizationProviderId}/organizations/{organizationId}/roles/', 'verb' => 'GET'], ], ]; \ No newline at end of file diff --git a/lib/Controller/OrganizationController.php b/lib/Controller/OrganizationController.php new file mode 100644 index 0000000..26948d0 --- /dev/null +++ b/lib/Controller/OrganizationController.php @@ -0,0 +1,61 @@ +handleErrors(function () { + return array_keys($this->oganizationProviderManager->getOrganizationProviders()); + }); + } + + #[NoAdminRequired] + public function getOrganization(string $organizationProviderId, int $organizationId): JSONResponse { + return $this->handleErrors(function () use ($organizationProviderId, $organizationId) { + $organizationProvider = $this->oganizationProviderManager->getOrganizationProvider($organizationProviderId); + + return $organizationProvider->getOrganization($organizationId); + }); + } + + #[NoAdminRequired] + public function getTopLevelOrganizations(string $organizationProviderId): JSONResponse { + return $this->handleErrors(function () use ($organizationProviderId) { + $organizationProvider = $this->oganizationProviderManager->getOrganizationProvider($organizationProviderId); + + return $organizationProvider->getSubOrganizations(); + }); + } + + #[NoAdminRequired] + public function getSubOrganizations(string $organizationProviderId, int $parentOrganizationId): JSONResponse { + return $this->handleErrors(function () use ($organizationProviderId, $parentOrganizationId) { + $organizationProvider = $this->oganizationProviderManager->getOrganizationProvider($organizationProviderId); + + return $organizationProvider->getSubOrganizations($parentOrganizationId); + }); + } + + #[NoAdminRequired] + public function getRoles(string $organizationProviderId, int $organizationId): JSONResponse { + return $this->handleErrors(function () use ($organizationProviderId, $organizationId) { + $organizationProvider = $this->oganizationProviderManager->getOrganizationProvider($organizationProviderId); + + return $organizationProvider->getRolesOfOrganization($organizationId); + }); + } +} \ No newline at end of file