0
0
Fork 0
mirror of https://github.com/verdigado/organization_folders.git synced 2024-11-23 21:20:28 +01:00

Added organization controller

This commit is contained in:
Jonathan Treffler 2024-11-19 19:56:15 +01:00
parent e910ed5134
commit 01d63a7f76
2 changed files with 66 additions and 0 deletions

View file

@ -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'],
],
];

View file

@ -0,0 +1,61 @@
<?php
namespace OCA\OrganizationFolders\Controller;
use OCP\AppFramework\Http\JSONResponse;
use OCP\AppFramework\Http\Attribute\NoAdminRequired;
use OCA\OrganizationFolders\OrganizationProvider\OrganizationProviderManager;
class OrganizationController extends BaseController {
use Errors;
public function __construct(
private OrganizationProviderManager $oganizationProviderManager,
) {
parent::__construct();
}
#[NoAdminRequired]
public function getOrganizationProviders(): JSONResponse {
return $this->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);
});
}
}