moved login from grpc_client

This commit is contained in:
filipriec
2025-03-31 10:23:23 +02:00
parent 81f0527085
commit ac833294c4
2 changed files with 24 additions and 13 deletions

View File

@@ -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)
}
}

View 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)
}
}