splitting proto conf, still some errors, fixing
This commit is contained in:
7
build.rs
7
build.rs
@@ -4,7 +4,12 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
.build_server(true)
|
||||
.file_descriptor_set_path("src/proto/descriptor.bin")
|
||||
.compile_protos(
|
||||
&["proto/adresar.proto", "proto/uctovnictvo.proto"],
|
||||
&[
|
||||
"proto/common.proto",
|
||||
"proto/adresar.proto",
|
||||
"proto/uctovnictvo.proto",
|
||||
"proto/table_structure.proto"
|
||||
],
|
||||
&["proto"],
|
||||
)?;
|
||||
Ok(())
|
||||
|
||||
@@ -1,16 +1,17 @@
|
||||
// proto/adresar.proto
|
||||
syntax = "proto3";
|
||||
|
||||
package multieko2.adresar;
|
||||
|
||||
import "common.proto";
|
||||
import "table_structure.proto";
|
||||
|
||||
service Adresar {
|
||||
rpc PostAdresar (PostAdresarRequest) returns (AdresarResponse);
|
||||
rpc GetAdresar (GetAdresarRequest) returns (AdresarResponse);
|
||||
rpc PutAdresar (PutAdresarRequest) returns (AdresarResponse);
|
||||
rpc DeleteAdresar (DeleteAdresarRequest) returns (DeleteAdresarResponse);
|
||||
rpc GetAdresarCount (Empty) returns (CountResponse);
|
||||
rpc GetAdresarByPosition (PositionRequest) returns (AdresarResponse);
|
||||
rpc GetTableStructure (Empty) returns (TableStructureResponse);
|
||||
rpc GetAdresarCount (common.Empty) returns (common.CountResponse);
|
||||
rpc GetAdresarByPosition (common.PositionRequest) returns (AdresarResponse);
|
||||
}
|
||||
|
||||
message GetAdresarRequest {
|
||||
@@ -80,24 +81,3 @@ message PutAdresarRequest {
|
||||
message DeleteAdresarResponse {
|
||||
bool success = 1;
|
||||
}
|
||||
|
||||
message Empty {}
|
||||
|
||||
message CountResponse {
|
||||
int64 count = 1;
|
||||
}
|
||||
|
||||
message PositionRequest {
|
||||
int64 position = 1;
|
||||
}
|
||||
|
||||
message TableStructureResponse {
|
||||
repeated TableColumn columns = 1;
|
||||
}
|
||||
|
||||
message TableColumn {
|
||||
string name = 1;
|
||||
string data_type = 2;
|
||||
bool is_nullable = 3;
|
||||
bool is_primary_key = 4;
|
||||
}
|
||||
|
||||
6
proto/common.proto
Normal file
6
proto/common.proto
Normal file
@@ -0,0 +1,6 @@
|
||||
syntax = "proto3";
|
||||
package multieko2.common;
|
||||
|
||||
message Empty {}
|
||||
message CountResponse { int64 count = 1; }
|
||||
message PositionRequest { int64 position = 1; }
|
||||
20
proto/table_structure.proto
Normal file
20
proto/table_structure.proto
Normal file
@@ -0,0 +1,20 @@
|
||||
syntax = "proto3";
|
||||
package multieko2.table_structure;
|
||||
|
||||
import "common.proto";
|
||||
|
||||
message TableStructureResponse {
|
||||
repeated TableColumn columns = 1;
|
||||
}
|
||||
|
||||
message TableColumn {
|
||||
string name = 1;
|
||||
string data_type = 2;
|
||||
bool is_nullable = 3;
|
||||
bool is_primary_key = 4;
|
||||
}
|
||||
|
||||
service TableStructureService {
|
||||
rpc GetAdresarTableStructure (common.Empty) returns (TableStructureResponse);
|
||||
rpc GetUctovnictvoTableStructure (common.Empty) returns (TableStructureResponse);
|
||||
}
|
||||
@@ -1,17 +1,15 @@
|
||||
// proto/uctovnictvo.proto
|
||||
syntax = "proto3";
|
||||
|
||||
package multieko2.uctovnictvo;
|
||||
|
||||
import "adresar.proto";
|
||||
import "common.proto";
|
||||
|
||||
service Uctovnictvo {
|
||||
rpc PostUctovnictvo (PostUctovnictvoRequest) returns (UctovnictvoResponse);
|
||||
rpc GetUctovnictvo (GetUctovnictvoRequest) returns (UctovnictvoResponse);
|
||||
rpc GetUctovnictvoCount (multieko2.adresar.Empty) returns (multieko2.adresar.CountResponse);
|
||||
rpc GetUctovnictvoByPosition (multieko2.adresar.PositionRequest) returns (UctovnictvoResponse);
|
||||
rpc GetUctovnictvoCount (common.Empty) returns (common.CountResponse);
|
||||
rpc GetUctovnictvoByPosition (common.PositionRequest) returns (UctovnictvoResponse);
|
||||
rpc PutUctovnictvo (PutUctovnictvoRequest) returns (UctovnictvoResponse);
|
||||
rpc GetTableStructure (multieko2.adresar.Empty) returns (multieko2.adresar.TableStructureResponse);
|
||||
}
|
||||
|
||||
message PostUctovnictvoRequest {
|
||||
|
||||
@@ -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