mirror of
http://124.126.16.154:8888/singularity/hdk-auth.git
synced 2026-01-15 07:25:05 +08:00
feat(UserRpc): 新增用户搜索功能并优化代码结构
- 新增 search 方法,用于搜索用户信息 - 优化 existing 方法,提高代码可读性 - 统一代码格式,增加空格和换行,提高可维护性
This commit is contained in:
@@ -33,6 +33,7 @@ class UserRpc
|
||||
|
||||
/**
|
||||
* @param $name
|
||||
*
|
||||
* @return bool
|
||||
* @throws GuzzleException
|
||||
*/
|
||||
@@ -40,40 +41,68 @@ class UserRpc
|
||||
{
|
||||
try {
|
||||
$this->requestService->setOptions([
|
||||
[
|
||||
'headers' => [
|
||||
'Accept-Language' => $this->translator->getLocale(),
|
||||
],
|
||||
[
|
||||
'headers' => [
|
||||
'Accept-Language' => $this->translator->getLocale(),
|
||||
],
|
||||
])->requestGet(
|
||||
'/rpc/user/alive', params: [
|
||||
'username' => urlencode($name),
|
||||
]
|
||||
);
|
||||
],
|
||||
])->requestGet(
|
||||
'/rpc/user/alive',
|
||||
params: [
|
||||
'username' => urlencode($name),
|
||||
],
|
||||
);
|
||||
return true;
|
||||
} catch (ClientException) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $username
|
||||
*
|
||||
* @return User
|
||||
* @throws GuzzleException
|
||||
*/
|
||||
public function search($username): User
|
||||
{
|
||||
$response = $this->requestService->setOptions([
|
||||
[
|
||||
'headers' => [
|
||||
'Accept-Language' => $this->translator->getLocale(),
|
||||
],
|
||||
],
|
||||
])->requestGet(
|
||||
'/rpc/user/alive',
|
||||
params: [
|
||||
'username' => urlencode($username),
|
||||
],
|
||||
);
|
||||
$content = $response->getBody()->getContents();
|
||||
$user = Json::decode($content);
|
||||
return User::make($user);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $uid
|
||||
*
|
||||
* @return User
|
||||
* @throws GuzzleException
|
||||
*/
|
||||
public function detail($uid): User
|
||||
{
|
||||
$response = $this->requestService->setOptions([
|
||||
[
|
||||
'headers' => [
|
||||
'Accept-Language' => $this->translator->getLocale(),
|
||||
],
|
||||
[
|
||||
'headers' => [
|
||||
'Accept-Language' => $this->translator->getLocale(),
|
||||
],
|
||||
])->requestGet(
|
||||
'/rpc/user/detail', params: [
|
||||
'uid' => $uid,
|
||||
]
|
||||
);
|
||||
],
|
||||
])->requestGet(
|
||||
'/rpc/user/detail',
|
||||
params: [
|
||||
'uid' => $uid,
|
||||
],
|
||||
);
|
||||
|
||||
$content = $response->getBody()->getContents();
|
||||
$user = Json::decode($content);
|
||||
@@ -82,21 +111,22 @@ class UserRpc
|
||||
|
||||
/**
|
||||
* @param $data
|
||||
*
|
||||
* @return User
|
||||
* @throws GuzzleException
|
||||
*/
|
||||
public function create($data): User
|
||||
{
|
||||
$response = $this->requestService->setOptions([
|
||||
[
|
||||
'headers' => [
|
||||
'Accept-Language' => $this->translator->getLocale(),
|
||||
],
|
||||
[
|
||||
'headers' => [
|
||||
'Accept-Language' => $this->translator->getLocale(),
|
||||
],
|
||||
])->requestPost(
|
||||
'/rpc/user/create',
|
||||
data: $data
|
||||
);
|
||||
],
|
||||
])->requestPost(
|
||||
'/rpc/user/create',
|
||||
data: $data,
|
||||
);
|
||||
|
||||
$content = $response->getBody()->getContents();
|
||||
$user = Json::decode($content);
|
||||
@@ -107,24 +137,25 @@ class UserRpc
|
||||
/**
|
||||
* @param $uid
|
||||
* @param $data
|
||||
*
|
||||
* @return User
|
||||
* @throws GuzzleException
|
||||
*/
|
||||
public function update($uid, $data): User
|
||||
{
|
||||
$response = $this->requestService->setOptions([
|
||||
[
|
||||
'headers' => [
|
||||
'Accept-Language' => $this->translator->getLocale(),
|
||||
],
|
||||
[
|
||||
'headers' => [
|
||||
'Accept-Language' => $this->translator->getLocale(),
|
||||
],
|
||||
])->requestPost(
|
||||
'/rpc/user/update',
|
||||
params: [
|
||||
'uid' => $uid,
|
||||
],
|
||||
data: $data,
|
||||
);
|
||||
],
|
||||
])->requestPost(
|
||||
'/rpc/user/update',
|
||||
params: [
|
||||
'uid' => $uid,
|
||||
],
|
||||
data: $data,
|
||||
);
|
||||
|
||||
$content = $response->getBody()->getContents();
|
||||
$user = Json::decode($content);
|
||||
@@ -133,21 +164,22 @@ class UserRpc
|
||||
|
||||
/**
|
||||
* @param $uid_arr
|
||||
*
|
||||
* @return AnonymousResourceCollection<User>
|
||||
* @throws GuzzleException
|
||||
*/
|
||||
public function list($uid_arr): AnonymousResourceCollection
|
||||
{
|
||||
$response = $this->requestService->setOptions([
|
||||
[
|
||||
'headers' => [
|
||||
'Accept-Language' => $this->translator->getLocale(),
|
||||
],
|
||||
[
|
||||
'headers' => [
|
||||
'Accept-Language' => $this->translator->getLocale(),
|
||||
],
|
||||
])->requestGet(
|
||||
'/rpc/user',
|
||||
data: $uid_arr
|
||||
);
|
||||
],
|
||||
])->requestGet(
|
||||
'/rpc/user',
|
||||
data: $uid_arr,
|
||||
);
|
||||
|
||||
$content = $response->getBody()->getContents();
|
||||
$users = Json::decode($content);
|
||||
@@ -157,21 +189,22 @@ class UserRpc
|
||||
|
||||
/**
|
||||
* @param $data
|
||||
*
|
||||
* @return User
|
||||
* @throws GuzzleException
|
||||
*/
|
||||
public function checkNamePass($data): User
|
||||
{
|
||||
$response = $this->requestService->setOptions([
|
||||
[
|
||||
'headers' => [
|
||||
'Accept-Language' => $this->translator->getLocale(),
|
||||
],
|
||||
[
|
||||
'headers' => [
|
||||
'Accept-Language' => $this->translator->getLocale(),
|
||||
],
|
||||
])->requestPost(
|
||||
'/rpc/user/signIn',
|
||||
data: $data
|
||||
);
|
||||
],
|
||||
])->requestPost(
|
||||
'/rpc/user/signIn',
|
||||
data: $data,
|
||||
);
|
||||
|
||||
$content = $response->getBody()->getContents();
|
||||
$user = Json::decode($content);
|
||||
|
||||
Reference in New Issue
Block a user