Files
casadoc/public/userportal/api/homes.php
T
2026-07-27 21:04:07 +03:00

27 lines
799 B
PHP

<?php
require __DIR__ . '/_bootstrap.php';
/**
* @OA\Get(
* path="/homes.php",
* tags={"Homes"},
* summary="My properties",
* security={{"bearerAuth":{}}},
* @OA\Response(response=200, description="OK", @OA\JsonContent(
* @OA\Property(property="data", type="array", @OA\Items(ref="#/components/schemas/Home"))
* )),
* @OA\Response(response=401, ref="#/components/responses/Unauthorized")
* )
*/
require_method('GET');
$user = require_auth($pdo);
$stmt = $pdo->prepare('SELECT * FROM home WHERE iduser = ? ORDER BY idhome DESC');
$stmt->execute([$user['id']]);
$rows = $stmt->fetchAll();
$counts = home_counts($pdo, array_column($rows, 'idhome'));
$homes = array_map(fn ($h) => present_home($h, true, $counts[(int) $h['idhome']] ?? null), $rows);
json_data($homes);