Compare commits

...

4 Commits

Author SHA1 Message Date
filipriec
dd4d9e88c6 ready to move gRPC into a single services folder, time to do the changes now 2025-03-31 09:39:47 +02:00
filipriec
f66d67c238 grpc_service moved 2025-03-31 07:13:24 +02:00
filipriec
9cf25afa52 moving grpc_client, needs import fixes 2025-03-31 07:08:51 +02:00
filipriec
2ed2419f9e Add auth service client and auth state fields 2025-03-30 21:44:45 +02:00
16 changed files with 47 additions and 12 deletions

View File

@@ -5,6 +5,7 @@ pub mod config;
pub mod state;
pub mod components;
pub mod modes;
pub mod services;
pub use ui::run_ui;

View File

@@ -1,10 +1,11 @@
// src/modes/canvas/common.rs
use crate::config::binds::config::Config;
use crate::tui::terminal::grpc_client::GrpcClient;
use crate::tui::terminal::core::TerminalCore;
use crate::state::pages::form::FormState;
use crate::state::state::AppState;
use crate::services::grpc_client::GrpcClient;
use common::proto::multieko2::adresar::{PostAdresarRequest, PutAdresarRequest};
/// Main handler for common core actions

View File

@@ -2,12 +2,11 @@
// TODO THIS is freaking bloated with functions it never uses REFACTOR 200 LOC can be gone
use crossterm::event::{KeyEvent, KeyCode, KeyModifiers};
use crate::tui::terminal::{
grpc_client::GrpcClient,
};
use crate::config::binds::config::Config;
use crate::state::pages::form::FormState;
use crate::modes::canvas::common;
use crate::services::grpc_client::GrpcClient;
pub async fn handle_edit_event_internal(
key: KeyEvent,

View File

@@ -5,8 +5,8 @@ use crossterm::event::{KeyEvent};
use crate::config::binds::config::Config;
use crate::state::pages::form::FormState;
use crate::state::pages::auth::AuthState;
use crate::services::grpc_client::GrpcClient;
use crate::config::binds::key_sequences::KeySequenceTracker;
use crate::tui::terminal::grpc_client::GrpcClient;
#[derive(PartialEq)]
enum CharType {

View File

@@ -1,8 +1,8 @@
// src/modes/handlers/command_mode.rs
use crossterm::event::{KeyEvent, KeyCode, KeyModifiers};
use crate::tui::terminal::grpc_client::GrpcClient;
use crate::config::binds::config::Config;
use crate::services::grpc_client::GrpcClient;
use crate::state::pages::form::FormState;
use crate::tui::controls::commands::CommandHandler;
use crate::tui::terminal::core::TerminalCore;

View File

@@ -3,8 +3,8 @@ use crossterm::event::Event;
use crossterm::cursor::SetCursorStyle;
use crate::tui::terminal::{
core::TerminalCore,
grpc_client::GrpcClient,
};
use crate::services::grpc_client::GrpcClient;
use crate::tui::controls::commands::CommandHandler;
use crate::config::binds::config::Config;
use crate::state::pages::form::FormState;

View File

@@ -0,0 +1 @@
// src/services/adresar.rs

View File

View File

@@ -1,4 +1,4 @@
// src/tui/terminal/grpc_client.rs
// src/services/grpc_client.rs
use tonic::transport::Channel;
use common::proto::multieko2::adresar::adresar_client::AdresarClient;
@@ -10,11 +10,17 @@ 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 {
@@ -22,11 +28,13 @@ 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,
})
}
@@ -65,4 +73,10 @@ 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,13 @@
// services/mod.rs
pub mod grpc_client;
pub mod adresar;
pub mod table;
pub mod profile;
pub mod auth;
pub use grpc_client::*;
pub use adresar::*;
pub use table::*;
pub use profile::*;
pub use auth::*;

View File

@@ -0,0 +1 @@
// src/services/profile.rs

View File

@@ -0,0 +1 @@
// src/services/table.rs

View File

@@ -9,6 +9,9 @@ pub struct AuthState {
pub error_message: Option<String>,
pub current_field: usize,
pub current_cursor_pos: usize,
pub auth_token: Option<String>,
pub user_id: Option<String>,
pub role: Option<String>,
}
impl AuthState {
@@ -20,6 +23,9 @@ impl AuthState {
error_message: None,
current_field: 0,
current_cursor_pos: 0,
auth_token: None,
user_id: None,
role: None,
}
}
}

View File

@@ -1,6 +1,6 @@
// src/tui/functions/form.rs
use crate::state::pages::form::FormState;
use crate::tui::terminal::GrpcClient;
use crate::services::grpc_client::GrpcClient;
use common::proto::multieko2::adresar::AdresarResponse;
pub async fn handle_action(

View File

@@ -1,9 +1,7 @@
// src/tui/terminal.rs
pub mod core;
pub mod grpc_client;
pub mod event_reader;
pub use core::TerminalCore;
pub use grpc_client::GrpcClient;
pub use event_reader::EventReader;

View File

@@ -1,7 +1,7 @@
// src/ui/handlers/ui.rs
use crate::tui::terminal::TerminalCore;
use crate::tui::terminal::GrpcClient;
use crate::services::grpc_client::GrpcClient;
use crate::tui::controls::CommandHandler;
use crate::tui::terminal::EventReader;
use crate::config::colors::themes::Theme;