/** Datei: plugins/tenants/library/ARUNOX/Plugins/Tenants/Users/API/v1/Routes.php **/ * @copyright 2025 ARUNOX * @version 1.1.0 * * @since 1.0.0 File is created */ namespace ARUNOX\Plugins\Tenants\Users\API\v1; use ARUNOX\Core\Hooks; use ARUNOX\Core\Router; use ARUNOX\Plugins\Users; class Routes { public static function register() : void { Router::addAll( Controller::class ); // Router::get('/api/v1/tenants/{id}/users', [ Controller::class, 'getAll' ]); // Router::get('/api/v1/tenants/create', [ Controller::class, 'restConfigCreate' ]); // Router::post('/api/v1/tenants', [ Controller::class, 'create' ]); // Router::get('/api/v1/tenants/{id}/users/{id}', [ Controller::class, 'get' ]); // Router::put('/api/v1/tenants/{id}', [ Controller::class, 'save' ]); // Router::patch('/api/v1/tenants/{id}/status', [ Controller::class, 'toggleStatus' ]); // Router::get('/api/v1/tenants/{id}/delete', [ Controller::class, 'restConfigDelete' ]); // Router::delete('/api/v1/tenants/{id}', [ Controller::class, 'delete' ]); Hooks::add('router::get->api.v1.rest.routes', function( $routes ) { if( !Users\Model::isSuperadmin() ) return $routes; $routes[] = [ "path" => "/tenants/{id}/users/{id}", "label" => "Benutzer", ]; return $routes; }); } } /** Datei: plugins/tenants/library/ARUNOX/Plugins/Tenants/Users/API/v1/Controller.php **/ * @copyright 2025 ARUNOX * @version 1.1.0 * * @since 1.0.0 File is created */ namespace ARUNOX\Plugins\Tenants\Users\API\v1; use ARUNOX\HTTP; use ARUNOX\Core\Hooks; use ARUNOX\Plugins\REST; use ARUNOX\Plugins\Users; use ARUNOX\Plugins\Tenants; use ARUNOX\API\BaseController; class Controller extends BaseController { /* ### VARIABLES ################################################ # */ protected static array $NOTIFY = [ "notfound" => "Benutzer nicht gefunden", ]; /* ### PUBLIC GET FUNCTIONS ##################################### # */ public function getAll( int $tenant_id ) : HTTP\Response { $results = Users\Model::getAll([ "tenant_id__meta" => $tenant_id ]); return $this->jsonResponse( $results ); } public function get( int $tenant_id, int $user_id ) : HTTP\Response { $result = Users\Model::get([ "id" => $user_id, "tenant_id__meta" => $tenant_id ]); if( $result ) { Users\API\v1\Controller::restConfigDetails( $result ) ->setBacklink( "/tenants/{$tenant_id}#users" ); } else REST\Response::addNotify( "danger", static::getNotify("notfound") ); return REST\Response::jsonResponse(); } /* ### PUBLIC REST FUNCTIONS #################################### # */ public static function restConfigTable() : REST\Generator\Base\BaseGenerator { $table = Users\API\v1\Controller::restConfigTable() ->setApi( "/tenants/{id}/users" ) ->setAction( "/api/v1/tenants/{tenant_id}/users/{id}" ); foreach( $table->get()->getButtons() as $button ) { $action = $button->getAction(); if( $action["route"] != "/users/{id}" ) continue; $action["route"] = "/tenants/{tenant_id}/users/{id}"; $button->setAction( ...$action ); break; } return $table; } }