76 lines
2.6 KiB
PHP
76 lines
2.6 KiB
PHP
<?php
|
|
|
|
use Psr\Http\Message\ResponseInterface as Response;
|
|
use Psr\Http\Message\ServerRequestInterface as Request;
|
|
use DI\Bridge\Slim\Bridge;
|
|
use Slim\Routing\RouteCollectorProxy;
|
|
use App\Auth\AdminMiddleware;
|
|
use App\Auth\AuthController;
|
|
use App\Auth\AuthMiddleware;
|
|
use App\View\ViewController;
|
|
use App\Text\TextController;
|
|
use App\Node\NodeController;
|
|
use App\Plan\PlanController;
|
|
use App\ScheduledNode\ScheduledNodeController;
|
|
|
|
$container = require __DIR__ . '/container.php';
|
|
$app = Bridge::create($container);
|
|
|
|
// change first param to false for production
|
|
$app->addErrorMiddleware(true, true, true);
|
|
|
|
// Public routes (no auth required)
|
|
$app->get('/login', [ViewController::class, 'login']);
|
|
$app->get('/register', [ViewController::class, 'register']);
|
|
$app->post('/api/auth/login', [AuthController::class, 'login']);
|
|
$app->post('/api/auth/register', [AuthController::class, 'register']);
|
|
|
|
// Authenticated routes (any logged-in user)
|
|
$app->group('', function (RouteCollectorProxy $group) {
|
|
$group->get('/', [ViewController::class, 'home']);
|
|
$group->get('/home', [ViewController::class, 'home']);
|
|
$group->get('/today', [ViewController::class, 'today']);
|
|
$group->get('/texts', [ViewController::class, 'userTexts']);
|
|
$group->get('/texts/{textId}', [ViewController::class, 'userText']);
|
|
|
|
$group->post('/api/auth/logout', [AuthController::class, 'logout']);
|
|
$group->get('/api/auth/me', [AuthController::class, 'me']);
|
|
|
|
$group->get('/api/texts', [TextController::class, 'getMyTexts']);
|
|
$group->get(
|
|
'/api/texts/{textId}',
|
|
[TextController::class, 'getText']
|
|
);
|
|
$group->post('/api/texts', [TextController::class, 'createText']);
|
|
|
|
$group->get(
|
|
'/api/nodes/{textId}',
|
|
[NodeController::class, 'getNodesOfText']
|
|
);
|
|
$group->post('/api/nodes', [NodeController::class, 'createNode']);
|
|
$group->post(
|
|
'/api/nodes/bulk',
|
|
[NodeController::class, 'bulkCreateNodes']
|
|
);
|
|
|
|
$group->post('/api/plans', [PlanController::class, 'createPlan']);
|
|
|
|
$group->get(
|
|
'/api/scheduled-nodes',
|
|
[ScheduledNodeController::class, 'getScheduledNodes']
|
|
);
|
|
})->add(AuthMiddleware::class);
|
|
|
|
// Admin-only routes
|
|
$app->group('', function (RouteCollectorProxy $group) {
|
|
$group->get('/admin', [ViewController::class, 'admin']);
|
|
$group->get('/admin/texts', [ViewController::class, 'texts']);
|
|
$group->get(
|
|
'/admin/texts/{textId}',
|
|
[ViewController::class, 'text']
|
|
);
|
|
|
|
$group->get('/api/admin/texts', [TextController::class, 'getAllTexts']);
|
|
})->add(AdminMiddleware::class)->add(AuthMiddleware::class);
|
|
|
|
return $app;
|