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

38 lines
1.1 KiB
PHP

<?php
require __DIR__ . '/_bootstrap.php';
/**
* @OA\Get(
* path="/shares.php",
* tags={"Sharing"},
* summary="Sharing conditions for my home",
* 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", type="array", @OA\Items(ref="#/components/schemas/Share"))
* )),
* @OA\Response(response=403, ref="#/components/responses/Forbidden")
* )
*/
require_method('GET');
$user = require_auth($pdo);
$idhome = (int) query('idhome', 0);
if ($idhome <= 0) {
json_error(422, 'idhome is required');
}
if (!user_owns_home($pdo, $user, $idhome)) {
json_error(403, 'No access to this home');
}
$stmt = $pdo->prepare(
'SELECT hs.*, sr.role_name, sr.description AS role_description, sr.permissions AS role_permissions
FROM home_sharing hs
LEFT JOIN sharing_roles sr ON sr.idrole = hs.role_id
WHERE hs.idhome = ?
ORDER BY hs.idsharing DESC'
);
$stmt->execute([$idhome]);
json_data(array_map('present_share', $stmt->fetchAll()));