Deploy from Lumerel

This commit is contained in:
Lumerel Deploy
2026-02-16 22:17:38 +00:00
commit 2af9090a8e
19 changed files with 934 additions and 0 deletions

114
public/index.php Normal file
View File

@@ -0,0 +1,114 @@
<?php
require_once __DIR__ . '/../vendor/autoload.php';
require_once __DIR__ . '/../src/db.php';
use App\Controllers\AuthController;
use App\Controllers\ProjectController;
use App\Controllers\TaskController;
// Simple routing
$requestUri = $_SERVER['REQUEST_URI'];
$method = $_SERVER['REQUEST_METHOD'];
// Headers for JSON responses
header('Content-Type: application/json');
try {
switch (true) {
case $requestUri === '/api/register' && $method === 'POST':
$data = json_decode(file_get_contents('php://input'), true);
$authController = new AuthController();
echo json_encode($authController->register(
$data['name'],
$data['email'],
$data['password']
));
break;
case $requestUri === '/api/login' && $method === 'POST':
$data = json_decode(file_get_contents('php://input'), true);
$authController = new AuthController();
echo json_encode($authController->login(
$data['email'],
$data['password']
));
break;
case $requestUri === '/api/logout' && $method === 'POST':
$authController = new AuthController();
echo json_encode($authController->logout());
break;
case $requestUri === '/api/projects' && $method === 'GET':
if (!AuthController::isAuthenticated()) {
http_response_code(401);
echo json_encode(['error' => 'Unauthorized']);
break;
}
$projectController = new ProjectController();
echo json_encode($projectController->getUserProjects());
break;
case $requestUri === '/api/projects' && $method === 'POST':
if (!AuthController::isAuthenticated()) {
http_response_code(401);
echo json_encode(['error' => 'Unauthorized']);
break;
}
$data = json_decode(file_get_contents('php://input'), true);
$projectController = new ProjectController();
echo json_encode($projectController->createProject(
$data['name'],
$data['description']
));
break;
case preg_match('/^\/api\/projects\/(\d+)$/', $requestUri, $matches) && $method === 'GET':
if (!AuthController::isAuthenticated()) {
http_response_code(401);
echo json_encode(['error' => 'Unauthorized']);
break;
}
$projectController = new ProjectController();
echo json_encode($projectController->getProjectDetails($matches[1]));
break;
case $requestUri === '/api/tasks' && $method === 'POST':
if (!AuthController::isAuthenticated()) {
http_response_code(401);
echo json_encode(['error' => 'Unauthorized']);
break;
}
$data = json_decode(file_get_contents('php://input'), true);
$taskController = new TaskController();
echo json_encode($taskController->createTask(
$data['name'],
$data['description'],
$data['project_id'],
$data['status'] ?? 'created'
));
break;
case preg_match('/^\/api\/tasks\/(\d+)\/status$/', $requestUri, $matches) && $method === 'PUT':
if (!AuthController::isAuthenticated()) {
http_response_code(401);
echo json_encode(['error' => 'Unauthorized']);
break;
}
$data = json_decode(file_get_contents('php://input'), true);
$taskController = new TaskController();
echo json_encode($taskController->updateTaskStatus(
$matches[1],
$data['status']
));
break;
default:
http_response_code(404);
echo json_encode(['error' => 'Not Found']);
break;
}
} catch (Exception $e) {
http_response_code(500);
echo json_encode(['error' => $e->getMessage()]);
}