anyhow used
This commit is contained in:
@@ -4,6 +4,7 @@ use crate::services::grpc_client::GrpcClient;
|
||||
use crate::state::pages::form::FormState;
|
||||
use crate::tui::functions::common::form::SaveOutcome;
|
||||
use crate::state::app::state::AppState;
|
||||
use anyhow::{Context, Result};
|
||||
|
||||
pub struct UiService;
|
||||
|
||||
@@ -13,7 +14,7 @@ impl UiService {
|
||||
app_state: &mut AppState,
|
||||
) -> Result<Vec<String>, Box<dyn std::error::Error>> {
|
||||
// Fetch profile tree
|
||||
let profile_tree = grpc_client.get_profile_tree().await?;
|
||||
let profile_tree = grpc_client.get_profile_tree().await.context("Failed to get profile tree")?;
|
||||
app_state.profile_tree = profile_tree;
|
||||
|
||||
// Fetch table structure
|
||||
@@ -32,8 +33,8 @@ impl UiService {
|
||||
pub async fn initialize_adresar_count(
|
||||
grpc_client: &mut GrpcClient,
|
||||
app_state: &mut AppState,
|
||||
) -> Result<(), Box<dyn std::error::Error>> {
|
||||
let total_count = grpc_client.get_adresar_count().await?;
|
||||
) -> Result<()> {
|
||||
let total_count = grpc_client.get_adresar_count().await.await.context("Failed to get adresar count")?;
|
||||
app_state.update_total_count(total_count);
|
||||
app_state.update_current_position(total_count.saturating_add(1)); // Start in new entry mode
|
||||
Ok(())
|
||||
@@ -42,8 +43,8 @@ impl UiService {
|
||||
pub async fn update_adresar_count(
|
||||
grpc_client: &mut GrpcClient,
|
||||
app_state: &mut AppState,
|
||||
) -> Result<(), Box<dyn std::error::Error>> {
|
||||
let total_count = grpc_client.get_adresar_count().await?;
|
||||
) -> Result<()> {
|
||||
let total_count = grpc_client.get_adresar_count().await.context("Failed to get adresar by position")?;
|
||||
app_state.update_total_count(total_count);
|
||||
Ok(())
|
||||
}
|
||||
@@ -53,7 +54,7 @@ impl UiService {
|
||||
_app_state: &mut AppState,
|
||||
form_state: &mut FormState,
|
||||
position: u64,
|
||||
) -> Result<String, Box<dyn std::error::Error>> {
|
||||
) -> Result<String> {
|
||||
match grpc_client.get_adresar_by_position(position).await {
|
||||
Ok(response) => {
|
||||
// Set the ID properly
|
||||
@@ -92,8 +93,8 @@ impl UiService {
|
||||
save_outcome: SaveOutcome,
|
||||
grpc_client: &mut GrpcClient,
|
||||
app_state: &mut AppState,
|
||||
form_state: &mut FormState, // Needed to potentially update position/ID
|
||||
) -> Result<(), Box<dyn std::error::Error>> {
|
||||
form_state: &mut FormState,
|
||||
) -> Result<()> {
|
||||
match save_outcome {
|
||||
SaveOutcome::CreatedNew(new_id) => {
|
||||
// A new record was created, update the count!
|
||||
|
||||
Reference in New Issue
Block a user