diff --git a/crm/Modules/Users/Controllers/UserController.php b/crm/Modules/Users/Controllers/UserController.php index 881042a..aa6867a 100644 --- a/crm/Modules/Users/Controllers/UserController.php +++ b/crm/Modules/Users/Controllers/UserController.php @@ -916,4 +916,51 @@ class UserController extends BaseController echo 'Erro interno'; } } + + /** + * API: Get recent activity + */ + public function apiGetRecentActivity(): void + { + try { + $this->requireAuth(); + + if (!Auth::isAdmin()) { + http_response_code(403); + header('Content-Type: application/json'); + echo json_encode(['error' => 'Acesso negado']); + exit; + } + + // Mock data for now - implement real activity tracking later + $activities = [ + [ + 'id' => 1, + 'user_id' => 1, + 'action' => 'login', + 'description' => 'Utilizador fez login', + 'created_at' => date('Y-m-d H:i:s') + ], + [ + 'id' => 2, + 'user_id' => 1, + 'action' => 'redirect_created', + 'description' => 'Criou novo redirect', + 'created_at' => date('Y-m-d H:i:s', strtotime('-1 hour')) + ] + ]; + + header('Content-Type: application/json'); + echo json_encode([ + 'success' => true, + 'data' => $activities + ]); + } catch (\Exception $e) { + ErrorReporter::report($e, ['context' => 'api_get_recent_activity']); + http_response_code(500); + header('Content-Type: application/json'); + echo json_encode(['error' => 'Erro interno do servidor']); + } + exit; + } } \ No newline at end of file diff --git a/crm/Modules/Users/Routes/api.php b/crm/Modules/Users/Routes/api.php index a504611..7a7fd3b 100644 --- a/crm/Modules/Users/Routes/api.php +++ b/crm/Modules/Users/Routes/api.php @@ -31,4 +31,10 @@ $router->delete( '/api/admin/users/{int:id}', [UserController::class, 'apiDeleteUser'], [AuthMiddleware::class, 'requireAuth'] +); + +$router->get( + '/api/admin/users/recent-activity', + [UserController::class, 'apiGetRecentActivity'], + [AuthMiddleware::class, 'requireAuth'] ); \ No newline at end of file diff --git a/crm/composer.json b/crm/composer.json index ecbd54a..0b5443a 100644 --- a/crm/composer.json +++ b/crm/composer.json @@ -8,13 +8,13 @@ }, "autoload": { "psr-4": { - "App\\": "app/", + "App\\": "./", "Database\\": "database/" }, "classmap": [ - "app/Modules/*/Models/", - "app/Modules/*/Services/", - "app/Modules/*/Controllers/" + "Modules/*/Models/", + "Modules/*/Services/", + "Modules/*/Controllers/" ] }, "autoload-dev": { diff --git a/crm/test_autoload.php b/crm/test_autoload.php new file mode 100644 index 0000000..b7126da --- /dev/null +++ b/crm/test_autoload.php @@ -0,0 +1,27 @@ +getMessage() . "\n"; +} + +try { + $class = new \App\Modules\Users\Controllers\UserController(); + echo "✓ UserController loaded successfully\n"; +} catch (Exception $e) { + echo "✗ Error loading UserController: " . $e->getMessage() . "\n"; +} + +try { + $class = new \App\Core\Router(); + echo "✓ Router loaded successfully\n"; +} catch (Exception $e) { + echo "✗ Error loading Router: " . $e->getMessage() . "\n"; +}