36 lines
1.1 KiB
PHP
36 lines
1.1 KiB
PHP
<?php
|
|
require __DIR__ . '/_bootstrap.php';
|
|
|
|
/**
|
|
* @OA\Get(
|
|
* path="/homes-shared.php",
|
|
* tags={"Sharing"},
|
|
* summary="Homes shared with me (status=accepted)",
|
|
* 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 h.* FROM home_sharing hs
|
|
JOIN home h ON h.idhome = hs.idhome
|
|
WHERE (hs.idshareduser = ? OR hs.shared_email = ?)
|
|
AND hs.status = 'accepted'
|
|
AND (hs.expiration_date IS NULL OR hs.expiration_date >= CURDATE())
|
|
GROUP BY h.idhome
|
|
ORDER BY h.idhome DESC"
|
|
);
|
|
$stmt->execute([$user['id'], $user['email']]);
|
|
|
|
$rows = $stmt->fetchAll();
|
|
|
|
$counts = home_counts($pdo, array_column($rows, 'idhome'));
|
|
$homes = array_map(fn ($h) => present_home($h, false, $counts[(int) $h['idhome']] ?? null), $rows);
|
|
|
|
json_data($homes);
|