<?php
session_start();
if (!isset($_SESSION['name'])) {
    http_response_code(401);
    echo json_encode(['message' => 'Unauthorized']);
    die;
}

require_once 'config/db.php';

$query = "SELECT * FROM items ORDER BY date ASC";
$stmt = $pdo->prepare($query);
$stmt->execute();

$items = $stmt->fetchAll(PDO::FETCH_ASSOC);

echo json_encode($items);
