splitting proto conf, still some errors, fixing
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
// src/adresar/handlers/get_adresar_by_position.rs
|
||||
use tonic::{Status};
|
||||
use sqlx::PgPool;
|
||||
use crate::proto::multieko2::adresar::{PositionRequest, AdresarResponse, GetAdresarRequest};
|
||||
use crate::proto::multieko2::adresar::{AdresarResponse, GetAdresarRequest};
|
||||
use crate::proto::multieko2::common::PositionRequest;
|
||||
use super::get_adresar;
|
||||
|
||||
pub async fn get_adresar_by_position(
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
// src/adresar/handlers/get_adresar_count.rs
|
||||
use tonic::Status;
|
||||
use sqlx::PgPool;
|
||||
use crate::proto::multieko2::adresar::{CountResponse, Empty};
|
||||
use crate::proto::multieko2::common::{CountResponse, Empty};
|
||||
|
||||
pub async fn get_adresar_count(
|
||||
db_pool: &PgPool,
|
||||
|
||||
@@ -6,3 +6,4 @@ pub mod proto;
|
||||
pub mod adresar;
|
||||
pub mod uctovnictvo;
|
||||
pub mod shared;
|
||||
pub mod table_structure;
|
||||
|
||||
Binary file not shown.
@@ -10,5 +10,13 @@ pub mod multieko2 {
|
||||
tonic::include_proto!("multieko2.uctovnictvo");
|
||||
}
|
||||
|
||||
pub mod common {
|
||||
tonic::include_proto!("multieko2.common");
|
||||
}
|
||||
|
||||
pub mod table_structure {
|
||||
tonic::include_proto!("multieko2.table_structure");
|
||||
}
|
||||
|
||||
pub const FILE_DESCRIPTOR_SET: &[u8] = include_bytes!("descriptor.bin");
|
||||
}
|
||||
|
||||
@@ -1,26 +1,36 @@
|
||||
// src/server/mod.rs
|
||||
use crate::table_structure::handlers;
|
||||
use tonic::{Request, Response, Status};
|
||||
use tonic_reflection::server::Builder as ReflectionBuilder;
|
||||
use crate::adresar::handlers::{
|
||||
post_adresar, get_adresar, put_adresar, delete_adresar, get_adresar_count, get_adresar_by_position, get_table_structure
|
||||
post_adresar, get_adresar, put_adresar, delete_adresar, get_adresar_count, get_adresar_by_position,
|
||||
};
|
||||
use crate::uctovnictvo::handlers::{
|
||||
post_uctovnictvo, get_uctovnictvo, get_uctovnictvo_count, get_uctovnictvo_by_position,
|
||||
put_uctovnictvo, get_table_structure as get_uctovnictvo_table_structure,
|
||||
put_uctovnictvo,
|
||||
};
|
||||
use crate::proto::multieko2::{
|
||||
common::{Empty, CountResponse, PositionRequest},
|
||||
table_structure::{TableStructureResponse, TableColumn},
|
||||
FILE_DESCRIPTOR_SET,
|
||||
};
|
||||
use crate::proto::multieko2::adresar::{
|
||||
adresar_server::{Adresar, AdresarServer},
|
||||
PostAdresarRequest, AdresarResponse, GetAdresarRequest, PutAdresarRequest,
|
||||
DeleteAdresarRequest, DeleteAdresarResponse, PositionRequest, CountResponse, Empty,
|
||||
TableStructureResponse,
|
||||
DeleteAdresarRequest, DeleteAdresarResponse,
|
||||
};
|
||||
use crate::proto::multieko2::uctovnictvo::{
|
||||
uctovnictvo_server::{Uctovnictvo, UctovnictvoServer},
|
||||
PostUctovnictvoRequest, UctovnictvoResponse, GetUctovnictvoRequest, PutUctovnictvoRequest,
|
||||
};
|
||||
use crate::proto::multieko2::table_structure::{
|
||||
table_structure_service_server::{TableStructureService, TableStructureServiceServer},
|
||||
TableStructureResponse
|
||||
};
|
||||
use crate::proto::multieko2::{
|
||||
common::{Empty, CountResponse, PositionRequest},
|
||||
table_structure::{TableStructureResponse, TableColumn}
|
||||
};
|
||||
|
||||
pub struct AdresarService {
|
||||
db_pool: sqlx::PgPool,
|
||||
@@ -30,6 +40,10 @@ pub struct UctovnictvoService {
|
||||
db_pool: sqlx::PgPool,
|
||||
}
|
||||
|
||||
pub struct TableStructureHandler {
|
||||
db_pool: sqlx::PgPool
|
||||
}
|
||||
|
||||
#[tonic::async_trait]
|
||||
impl Adresar for AdresarService {
|
||||
async fn post_adresar(
|
||||
@@ -79,14 +93,6 @@ impl Adresar for AdresarService {
|
||||
let response = get_adresar_by_position(&self.db_pool, request.into_inner()).await?;
|
||||
Ok(Response::new(response))
|
||||
}
|
||||
|
||||
async fn get_table_structure(
|
||||
&self,
|
||||
request: Request<Empty>,
|
||||
) -> Result<Response<TableStructureResponse>, Status> {
|
||||
let response = get_table_structure(&self.db_pool, request.into_inner()).await?;
|
||||
Ok(Response::new(response))
|
||||
}
|
||||
}
|
||||
|
||||
#[tonic::async_trait]
|
||||
@@ -99,7 +105,6 @@ impl Uctovnictvo for UctovnictvoService {
|
||||
Ok(Response::new(response))
|
||||
}
|
||||
|
||||
// Add this method
|
||||
async fn get_uctovnictvo(
|
||||
&self,
|
||||
request: Request<GetUctovnictvoRequest>,
|
||||
@@ -131,13 +136,22 @@ impl Uctovnictvo for UctovnictvoService {
|
||||
let response = put_uctovnictvo(&self.db_pool, request.into_inner()).await?;
|
||||
Ok(Response::new(response))
|
||||
}
|
||||
}
|
||||
|
||||
async fn get_table_structure(
|
||||
#[tonic::async_trait]
|
||||
impl TableStructureService for TableStructureHandler {
|
||||
async fn get_adresar_table_structure(
|
||||
&self,
|
||||
request: Request<Empty>,
|
||||
request: Request<crate::proto::multieko2::common::Empty>,
|
||||
) -> Result<Response<TableStructureResponse>, Status> {
|
||||
let response = get_uctovnictvo_table_structure(&self.db_pool, request.into_inner()).await?;
|
||||
Ok(Response::new(response))
|
||||
handlers::get_adresar_table_structure(&self.db_pool, request.into_inner()).await
|
||||
}
|
||||
|
||||
async fn get_uctovnictvo_table_structure(
|
||||
&self,
|
||||
request: Request<crate::proto::multieko2::common::Empty>,
|
||||
) -> Result<Response<TableStructureResponse>, Status> {
|
||||
handlers::get_uctovnictvo_table_structure(&self.db_pool, request.into_inner()).await
|
||||
}
|
||||
}
|
||||
|
||||
@@ -145,6 +159,7 @@ pub async fn run_server(db_pool: sqlx::PgPool) -> Result<(), Box<dyn std::error:
|
||||
let addr = "[::1]:50051".parse()?;
|
||||
let adresar_service = AdresarService { db_pool: db_pool.clone() };
|
||||
let uctovnictvo_service = UctovnictvoService { db_pool: db_pool.clone() };
|
||||
let table_structure_service = TableStructureHandler { db_pool: db_pool.clone() };
|
||||
|
||||
println!("Server listening on {}", addr);
|
||||
|
||||
@@ -156,6 +171,7 @@ pub async fn run_server(db_pool: sqlx::PgPool) -> Result<(), Box<dyn std::error:
|
||||
tonic::transport::Server::builder()
|
||||
.add_service(AdresarServer::new(adresar_service))
|
||||
.add_service(UctovnictvoServer::new(uctovnictvo_service))
|
||||
.add_service(TableStructureServiceServer::new(table_structure_service))
|
||||
.add_service(reflection_service)
|
||||
.serve(addr)
|
||||
.await?;
|
||||
|
||||
4
src/table_structure/handlers.rs
Normal file
4
src/table_structure/handlers.rs
Normal file
@@ -0,0 +1,4 @@
|
||||
// src/table_structure/handlers.rs
|
||||
pub mod table_structure;
|
||||
|
||||
pub use table_structure::{get_adresar_table_structure, get_uctovnictvo_table_structure};
|
||||
39
src/table_structure/handlers/table_structure.rs
Normal file
39
src/table_structure/handlers/table_structure.rs
Normal file
@@ -0,0 +1,39 @@
|
||||
// src/table_structure/handlers.rs
|
||||
use tonic::Status;
|
||||
use sqlx::PgPool;
|
||||
use crate::proto::multieko2::{
|
||||
table_structure::{TableStructureResponse, TableColumn},
|
||||
common::Empty
|
||||
};
|
||||
|
||||
pub async fn get_adresar_table_structure(
|
||||
_db_pool: &PgPool,
|
||||
_request: Empty,
|
||||
) -> Result<TableStructureResponse, Status> {
|
||||
let columns = vec![
|
||||
TableColumn {
|
||||
name: "firma".to_string(),
|
||||
data_type: "TEXT".to_string(),
|
||||
is_nullable: false,
|
||||
is_primary_key: false,
|
||||
},
|
||||
// ... other columns from original adresar handler
|
||||
];
|
||||
Ok(TableStructureResponse { columns })
|
||||
}
|
||||
|
||||
pub async fn get_uctovnictvo_table_structure(
|
||||
_db_pool: &PgPool,
|
||||
_request: Empty,
|
||||
) -> Result<TableStructureResponse, Status> {
|
||||
let columns = vec![
|
||||
TableColumn {
|
||||
name: "adresar_id".to_string(),
|
||||
data_type: "BIGINT".to_string(),
|
||||
is_nullable: false,
|
||||
is_primary_key: false,
|
||||
},
|
||||
// ... other columns from original uctovnictvo handler
|
||||
];
|
||||
Ok(TableStructureResponse { columns })
|
||||
}
|
||||
3
src/table_structure/mod.rs
Normal file
3
src/table_structure/mod.rs
Normal file
@@ -0,0 +1,3 @@
|
||||
// src/table_structure/mod.rs
|
||||
|
||||
pub mod handlers;
|
||||
@@ -1,7 +1,7 @@
|
||||
// src/uctovnictvo/handlers/get_uctovnictvo_count.rs
|
||||
use tonic::Status;
|
||||
use sqlx::PgPool;
|
||||
use crate::proto::multieko2::adresar::{CountResponse, Empty};
|
||||
use crate::proto::multieko2::common::{CountResponse, Empty};
|
||||
|
||||
pub async fn get_uctovnictvo_count(
|
||||
db_pool: &PgPool,
|
||||
|
||||
Reference in New Issue
Block a user