trying to do the count

This commit is contained in:
filipriec
2025-02-18 16:32:18 +01:00
parent 9ff6dada40
commit 02855c4c46
3 changed files with 49 additions and 2 deletions

View File

@@ -9,6 +9,7 @@ use std::io::{self, stdout};
use tonic::transport::Channel;
use crate::proto::multieko2::adresar_client::AdresarClient;
use crate::client::config::Config;
use crate::proto::multieko2::{Empty, CountResponse, PositionRequest, AdresarResponse};
use crate::proto::multieko2::PostAdresarRequest;
pub struct AppTerminal {
@@ -83,4 +84,18 @@ impl AppTerminal {
_ => Ok((false, format!("Action not recognized: {}", action))),
}
}
// Add a method to get the total count of Adresar entries
pub async fn get_adresar_count(&self) -> Result<u64, Box<dyn std::error::Error>> {
let request = tonic::Request::new(Empty {});
let response: CountResponse = self.grpc_client.get_adresar_count(request).await?.into_inner();
Ok(response.count as u64)
}
// Add a method to get an Adresar entry by its position
pub async fn get_adresar_by_position(&self, position: u64) -> Result<AdresarResponse, Box<dyn std::error::Error>> {
let request = tonic::Request::new(PositionRequest { position: position as i64 });
let response: AdresarResponse = self.grpc_client.get_adresar_by_position(request).await?.into_inner();
Ok(response)
}
}