improvement(API): fix inconsistencies in util.* + add chandler guid resolving funs

This commit is contained in:
celestora 2024-03-27 22:38:35 +02:00
parent 869712d73a
commit c4fb793333
3 changed files with 21 additions and 4 deletions

View file

@ -246,6 +246,9 @@ final class Users extends VKAPIRequestHandler
"notes_count" => (new Notes)->getUserNotesCount($usr) "notes_count" => (new Notes)->getUserNotesCount($usr)
]; ];
break; break;
case "guid":
$response[$i]->guid = $usr->getChandlerGUID();
break;
} }
} }

View file

@ -22,7 +22,7 @@ final class Utils extends VKAPIRequestHandler
"object_id" => (int) substr($screen_name, strlen("club")), "object_id" => (int) substr($screen_name, strlen("club")),
"type" => "group" "type" => "group"
]; ];
} } else $this->fail(104, "Not found");
} else { } else {
$user = (new Users)->getByShortURL($screen_name); $user = (new Users)->getByShortURL($screen_name);
if($user) { if($user) {
@ -39,8 +39,17 @@ final class Utils extends VKAPIRequestHandler
"type" => "group" "type" => "group"
]; ];
} }
return (object) []; $this->fail(104, "Not found");
} }
} }
function resolveGuid(string $guid): object
{
$user = (new Users)->getByChandlerUserId($guid);
if (is_null($user))
$this->fail(104, "Not found");
return $user->toVkApiStruct($this->getUser());
}
} }

View file

@ -44,9 +44,14 @@ class Users
return $alias->getUser(); return $alias->getUser();
} }
function getByChandlerUserId(string $cid): ?User
{
return $this->toUser($this->users->where("user", $cid)->fetch());
}
function getByChandlerUser(?ChandlerUser $user): ?User function getByChandlerUser(?ChandlerUser $user): ?User
{ {
return $user ? $this->toUser($this->users->where("user", $user->getId())->fetch()) : NULL; return $user ? $this->getByChandlerUserId($user->getId()) : NULL;
} }
function find(string $query, array $pars = [], string $sort = "id DESC"): Util\EntityStream function find(string $query, array $pars = [], string $sort = "id DESC"): Util\EntityStream