37 lines
1.0 KiB
PHP
37 lines
1.0 KiB
PHP
<?php
|
|
require __DIR__ . '/_bootstrap.php';
|
|
|
|
/**
|
|
* @OA\Get(
|
|
* path="/owner.php",
|
|
* tags={"Owners"},
|
|
* summary="Owner details",
|
|
* security={{"bearerAuth":{}}},
|
|
* @OA\Parameter(name="owner_id", in="query", required=true, @OA\Schema(type="integer")),
|
|
* @OA\Response(response=200, description="OK", @OA\JsonContent(
|
|
* @OA\Property(property="data", ref="#/components/schemas/Owner"))),
|
|
* @OA\Response(response=403, ref="#/components/responses/Forbidden"),
|
|
* @OA\Response(response=404, ref="#/components/responses/NotFound")
|
|
* )
|
|
*/
|
|
require_method('GET');
|
|
$user = require_auth($pdo);
|
|
$ownerId = (int) query('owner_id', 0);
|
|
|
|
if ($ownerId <= 0) {
|
|
json_error(422, 'owner_id is required');
|
|
}
|
|
|
|
$stmt = $pdo->prepare('SELECT * FROM property_owners WHERE owner_id = ? LIMIT 1');
|
|
$stmt->execute([$ownerId]);
|
|
$owner = $stmt->fetch();
|
|
|
|
if (!$owner) {
|
|
json_error(404, 'Owner not found');
|
|
}
|
|
if ((int) $owner['user_id'] !== (int) $user['id']) {
|
|
json_error(403, 'No access to this owner');
|
|
}
|
|
|
|
json_data(present_owner($owner));
|