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

40 lines
1.1 KiB
PHP

<?php
require __DIR__ . '/_bootstrap.php';
/**
* @OA\Get(
* path="/home.php",
* tags={"Homes"},
* summary="Property data",
* security={{"bearerAuth":{}}},
* @OA\Parameter(name="idhome", in="query", required=true, @OA\Schema(type="integer")),
* @OA\Response(response=200, description="OK", @OA\JsonContent(
* @OA\Property(property="data", ref="#/components/schemas/Home")
* )),
* @OA\Response(response=403, ref="#/components/responses/Forbidden"),
* @OA\Response(response=404, ref="#/components/responses/NotFound")
* )
*/
require_method('GET');
$user = require_auth($pdo);
$idhome = (int) query('idhome', 0);
if ($idhome <= 0) {
json_error(422, 'idhome is required');
}
if (!user_can_access_home($pdo, $user, $idhome)) {
json_error(403, 'No access to this home');
}
$stmt = $pdo->prepare('SELECT * FROM home WHERE idhome = ? LIMIT 1');
$stmt->execute([$idhome]);
$home = $stmt->fetch();
if (!$home) {
json_error(404, 'Home not found');
}
$counts = home_counts($pdo, [$idhome]);
json_data(present_home($home, (int) $home['iduser'] === (int) $user['id'], $counts[$idhome] ?? null));