Actualiser api/index.php
CI / PHP Syntax Check (push) Has been cancelled
CI / JavaScript Lint (push) Has been cancelled
CI / Docker Build Test (push) Has been cancelled
CI / Validate Translation Files (push) Has been cancelled
CI / Auto-merge develop → main (push) Has been cancelled
CI / Create GitHub Release (push) Has been cancelled
Security Scan (Trivy) / Trivy — Docker image scan (push) Has been cancelled
Security Scan (Trivy) / Trivy — Filesystem scan (push) Has been cancelled
CI / PHP Syntax Check (push) Has been cancelled
CI / JavaScript Lint (push) Has been cancelled
CI / Docker Build Test (push) Has been cancelled
CI / Validate Translation Files (push) Has been cancelled
CI / Auto-merge develop → main (push) Has been cancelled
CI / Create GitHub Release (push) Has been cancelled
Security Scan (Trivy) / Trivy — Docker image scan (push) Has been cancelled
Security Scan (Trivy) / Trivy — Filesystem scan (push) Has been cancelled
This commit is contained in:
@@ -12338,6 +12338,72 @@ function categoriesUpdate(PDO $db): void {
|
||||
echo json_encode(['success' => true]);
|
||||
}
|
||||
|
||||
function recipeLibraryList(PDO $db): void {
|
||||
$rows = $db->query("SELECT id, title, recipe_json, is_favorite, created_at FROM recipe_library ORDER BY is_favorite DESC, created_at DESC")->fetchAll();
|
||||
$recipes = [];
|
||||
foreach ($rows as $row) {
|
||||
$recipes[] = [
|
||||
'id' => (int)$row['id'],
|
||||
'title' => $row['title'],
|
||||
'recipe' => json_decode($row['recipe_json'], true),
|
||||
'is_favorite' => (bool)$row['is_favorite'],
|
||||
'created_at' => $row['created_at'],
|
||||
];
|
||||
}
|
||||
echo json_encode(['success' => true, 'recipes' => $recipes]);
|
||||
}
|
||||
|
||||
function recipeLibrarySave(PDO $db): void {
|
||||
$input = json_decode(file_get_contents('php://input'), true) ?? [];
|
||||
$id = (int)($input['id'] ?? 0);
|
||||
$recipe = $input['recipe'] ?? null;
|
||||
$title = trim($recipe['title'] ?? '');
|
||||
|
||||
if (!$recipe || $title === '') {
|
||||
echo json_encode(['success' => false, 'error' => 'title and recipe required']);
|
||||
return;
|
||||
}
|
||||
|
||||
$json = json_encode($recipe, JSON_UNESCAPED_UNICODE);
|
||||
|
||||
if ($id > 0) {
|
||||
$stmt = $db->prepare("SELECT id FROM recipe_library WHERE id = ?");
|
||||
$stmt->execute([$id]);
|
||||
if (!$stmt->fetch()) {
|
||||
echo json_encode(['success' => false, 'error' => 'recipe not found']);
|
||||
return;
|
||||
}
|
||||
$db->prepare("UPDATE recipe_library SET title = ?, recipe_json = ?, updated_at = CURRENT_TIMESTAMP WHERE id = ?")
|
||||
->execute([$title, $json, $id]);
|
||||
echo json_encode(['success' => true, 'id' => $id]);
|
||||
return;
|
||||
}
|
||||
|
||||
$db->prepare("INSERT INTO recipe_library (title, recipe_json) VALUES (?, ?)")->execute([$title, $json]);
|
||||
echo json_encode(['success' => true, 'id' => (int)$db->lastInsertId()]);
|
||||
}
|
||||
|
||||
function recipeLibraryDelete(PDO $db): void {
|
||||
$input = json_decode(file_get_contents('php://input'), true) ?? [];
|
||||
$id = (int)($input['id'] ?? 0);
|
||||
if ($id > 0) {
|
||||
$db->prepare("DELETE FROM recipe_library WHERE id = ?")->execute([$id]);
|
||||
}
|
||||
echo json_encode(['success' => true]);
|
||||
}
|
||||
|
||||
function recipeLibraryToggleFavorite(PDO $db): void {
|
||||
$input = json_decode(file_get_contents('php://input'), true) ?? [];
|
||||
$id = (int)($input['id'] ?? 0);
|
||||
if ($id <= 0) {
|
||||
echo json_encode(['success' => false, 'error' => 'id required']);
|
||||
return;
|
||||
}
|
||||
$db->prepare("UPDATE recipe_library SET is_favorite = 1 - is_favorite WHERE id = ?")->execute([$id]);
|
||||
$fav = (int)$db->query("SELECT is_favorite FROM recipe_library WHERE id = {$id}")->fetchColumn();
|
||||
echo json_encode(['success' => true, 'is_favorite' => (bool)$fav]);
|
||||
}
|
||||
|
||||
// ===== SHARED APP DATA FUNCTIONS =====
|
||||
|
||||
function appSettingsGet(PDO $db): void {
|
||||
|
||||
Reference in New Issue
Block a user