moved login from grpc_client
This commit is contained in:
@@ -10,17 +10,12 @@ use common::proto::multieko2::table_definition::{
|
||||
table_definition_client::TableDefinitionClient,
|
||||
ProfileTreeResponse
|
||||
};
|
||||
use common::proto::multieko2::auth::{
|
||||
auth_service_client::AuthServiceClient,
|
||||
LoginRequest, LoginResponse
|
||||
};
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct GrpcClient {
|
||||
adresar_client: AdresarClient<Channel>,
|
||||
table_structure_client: TableStructureServiceClient<Channel>,
|
||||
table_definition_client: TableDefinitionClient<Channel>,
|
||||
auth_client: AuthServiceClient<Channel>,
|
||||
}
|
||||
|
||||
impl GrpcClient {
|
||||
@@ -28,13 +23,11 @@ impl GrpcClient {
|
||||
let adresar_client = AdresarClient::connect("http://[::1]:50051").await?;
|
||||
let table_structure_client = TableStructureServiceClient::connect("http://[::1]:50051").await?;
|
||||
let table_definition_client = TableDefinitionClient::connect("http://[::1]:50051").await?;
|
||||
let auth_client = AuthServiceClient::connect("http://[::1]:50051").await?;
|
||||
|
||||
Ok(Self {
|
||||
adresar_client,
|
||||
table_structure_client,
|
||||
table_definition_client,
|
||||
auth_client,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -73,10 +66,4 @@ impl GrpcClient {
|
||||
let response = self.table_definition_client.get_profile_tree(request).await?;
|
||||
Ok(response.into_inner())
|
||||
}
|
||||
|
||||
pub async fn login(&mut self, identifier: String, password: String) -> Result<LoginResponse, Box<dyn std::error::Error>> {
|
||||
let request = tonic::Request::new(LoginRequest { identifier, password });
|
||||
let response = self.auth_client.login(request).await?.into_inner();
|
||||
Ok(response)
|
||||
}
|
||||
}
|
||||
|
||||
24
client/src/services/login.rs
Normal file
24
client/src/services/login.rs
Normal file
@@ -0,0 +1,24 @@
|
||||
// src/services/login.rs
|
||||
|
||||
use tonic::transport::Channel;
|
||||
use common::proto::multieko2::auth::{
|
||||
auth_service_client::AuthServiceClient,
|
||||
LoginRequest, LoginResponse
|
||||
};
|
||||
|
||||
pub struct AuthClient {
|
||||
client: AuthServiceClient<Channel>,
|
||||
}
|
||||
|
||||
impl AuthClient {
|
||||
pub async fn new() -> Result<Self, Box<dyn std::error::Error>> {
|
||||
let client = AuthServiceClient::connect("http://[::1]:50051").await?;
|
||||
Ok(Self { client })
|
||||
}
|
||||
|
||||
pub async fn login(&mut self, identifier: String, password: String) -> Result<LoginResponse, Box<dyn std::error::Error>> {
|
||||
let request = tonic::Request::new(LoginRequest { identifier, password });
|
||||
let response = self.client.login(request).await?.into_inner();
|
||||
Ok(response)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user