( ′∀`)σ≡σ☆))Д′)レ(゚∀゚;)ヘ=З=З=Зε≡(ノ´_ゝ`)ノ
<?php
require_once 'config.php';
header('Content-Type: application/json');
$action = $_POST['action'] ?? '';
if ($action === 'list_projects') {
// List all projects
try {
$stmt = $pdo->query('SELECT id, name, created_at FROM projects ORDER BY created_at DESC');
$projects = $stmt->fetchAll();
echo json_encode(['status' => 'success', 'projects' => $projects]);
} catch (PDOException $e) {
echo json_encode(['status' => 'error', 'message' => 'Failed to fetch projects']);
}
} elseif ($action === 'create_project') {
// Create a new project
$name = trim($_POST['name'] ?? '');
if (strlen($name) < 3) {
echo json_encode(['status' => 'error', 'message' => 'Project name too short']);
exit;
}
try {
$stmt = $pdo->prepare('INSERT INTO projects (name, created_at) VALUES (:name, NOW())');
$stmt->execute(['name' => $name]);
echo json_encode(['status' => 'success']);
} catch (PDOException $e) {
echo json_encode(['status' => 'error', 'message' => 'Failed to create project']);
}
} else {
echo json_encode(['status' => 'error', 'message' => 'Invalid action']);
}