23-01-2026
This commit is contained in:
parent
8fd1f4d451
commit
389d5d1820
59 changed files with 9642 additions and 883 deletions
185
app/Http/Controllers/API/NavigationController.php
Normal file
185
app/Http/Controllers/API/NavigationController.php
Normal file
|
|
@ -0,0 +1,185 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers\API;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Services\NavigationTreeService;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
|
||||
class NavigationController extends Controller
|
||||
{
|
||||
protected $navigationService;
|
||||
|
||||
public function __construct(NavigationTreeService $navigationService)
|
||||
{
|
||||
$this->navigationService = $navigationService;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gibt den kompletten Navigationsbaum zurück
|
||||
*
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function getNavigationTree(): JsonResponse
|
||||
{
|
||||
try {
|
||||
$tree = $this->navigationService->getNavigationTree();
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'data' => $tree,
|
||||
'meta' => [
|
||||
'total_nodes' => $this->navigationService->countNodes($tree),
|
||||
'generated_at' => now()->toIso8601String()
|
||||
]
|
||||
]);
|
||||
} catch (\Exception $e) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'error' => $e->getMessage()
|
||||
], 500);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gibt einen spezifischen Teil des Navigationsbaums zurück
|
||||
*
|
||||
* @param int $rootId Die ID des Root-Knotens
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function getNavigationSubTree(int $rootId): JsonResponse
|
||||
{
|
||||
try {
|
||||
$tree = $this->navigationService->getNavigationSubTree($rootId);
|
||||
|
||||
if (!$tree) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'error' => 'Navigation node not found'
|
||||
], 404);
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'data' => $tree,
|
||||
'meta' => [
|
||||
'total_nodes' => $this->navigationService->countNodes([$tree]),
|
||||
'generated_at' => now()->toIso8601String()
|
||||
]
|
||||
]);
|
||||
} catch (\Exception $e) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'error' => $e->getMessage()
|
||||
], 500);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gibt eine flache Liste aller Navigationspunkte zurück (ohne Hierarchie)
|
||||
*
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function getFlatNavigationList(): JsonResponse
|
||||
{
|
||||
try {
|
||||
$list = $this->navigationService->getFlatNavigationList();
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'data' => $list,
|
||||
'meta' => [
|
||||
'total_nodes' => count($list),
|
||||
'generated_at' => now()->toIso8601String()
|
||||
]
|
||||
]);
|
||||
} catch (\Exception $e) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'error' => $e->getMessage()
|
||||
], 500);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gibt nur die aktiven Navigationspunkte zurück
|
||||
*
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function getActiveNavigationTree(): JsonResponse
|
||||
{
|
||||
try {
|
||||
$tree = $this->navigationService->getNavigationTree(true);
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'data' => $tree,
|
||||
'meta' => [
|
||||
'total_nodes' => $this->navigationService->countNodes($tree),
|
||||
'generated_at' => now()->toIso8601String()
|
||||
]
|
||||
]);
|
||||
} catch (\Exception $e) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'error' => $e->getMessage()
|
||||
], 500);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gibt den Breadcrumb-Pfad für eine bestimmte Seite zurück
|
||||
*
|
||||
* @param int $pageId
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function getBreadcrumb(int $pageId): JsonResponse
|
||||
{
|
||||
try {
|
||||
$breadcrumb = $this->navigationService->getBreadcrumb($pageId);
|
||||
|
||||
if (empty($breadcrumb)) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'error' => 'Page not found'
|
||||
], 404);
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'data' => $breadcrumb,
|
||||
'meta' => [
|
||||
'depth' => count($breadcrumb),
|
||||
'generated_at' => now()->toIso8601String()
|
||||
]
|
||||
]);
|
||||
} catch (\Exception $e) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'error' => $e->getMessage()
|
||||
], 500);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Löscht den Navigation-Cache
|
||||
*
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function clearCache(): JsonResponse
|
||||
{
|
||||
try {
|
||||
$this->navigationService->clearCache();
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'message' => 'Navigation cache cleared successfully'
|
||||
]);
|
||||
} catch (\Exception $e) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'error' => $e->getMessage()
|
||||
], 500);
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue