diff --git a/build.rs b/build.rs index 52dc36a..7a8b1eb 100644 --- a/build.rs +++ b/build.rs @@ -4,7 +4,7 @@ fn main() -> Result<(), Box> { .build_server(true) .file_descriptor_set_path("src/proto/descriptor.bin") .compile_protos( - &["proto/api.proto", "proto/uctovnictvo.proto"], + &["proto/adresar.proto", "proto/uctovnictvo.proto"], &["proto"], )?; Ok(()) diff --git a/proto/api.proto b/proto/adresar.proto similarity index 64% rename from proto/api.proto rename to proto/adresar.proto index 99dd4b6..a2f41bb 100644 --- a/proto/api.proto +++ b/proto/adresar.proto @@ -1,25 +1,24 @@ -// proto/api.proto +// proto/adresar.proto syntax = "proto3"; -package multieko2; +package multieko2.adresar; 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); // New endpoint - rpc GetAdresarByPosition (PositionRequest) returns (AdresarResponse); // New endpoint - rpc GetTableStructure (Empty) returns (TableStructureResponse); // New endpoint for table structure + rpc GetAdresarCount (Empty) returns (CountResponse); + rpc GetAdresarByPosition (PositionRequest) returns (AdresarResponse); + rpc GetTableStructure (Empty) returns (TableStructureResponse); } -// Existing messages message GetAdresarRequest { - int64 id = 1; // The ID of the Adresar entry to retrieve + int64 id = 1; } message DeleteAdresarRequest { - int64 id = 1; // The ID of the Adresar entry to delete + int64 id = 1; } message PostAdresarRequest { @@ -79,28 +78,26 @@ message PutAdresarRequest { } message DeleteAdresarResponse { - bool success = 1; // Indicates whether the deletion was successful + bool success = 1; } -// New messages for the additional endpoints -message Empty {} // Empty request for count +message Empty {} message CountResponse { - int64 count = 1; // Response with the count of items + int64 count = 1; } message PositionRequest { - int64 position = 1; // Request with the position of the item to retrieve + int64 position = 1; } -// New messages for the table structure endpoint message TableStructureResponse { - repeated TableColumn columns = 1; // List of columns in the table + repeated TableColumn columns = 1; } message TableColumn { - string name = 1; // Name of the column - string data_type = 2; // Data type of the column (e.g., TEXT, INT, etc.) - bool is_nullable = 3; // Whether the column allows NULL values - bool is_primary_key = 4; // Whether the column is a primary key + string name = 1; + string data_type = 2; + bool is_nullable = 3; + bool is_primary_key = 4; } diff --git a/proto/uctovnictvo.proto b/proto/uctovnictvo.proto index b9f2e11..fb549ef 100644 --- a/proto/uctovnictvo.proto +++ b/proto/uctovnictvo.proto @@ -3,6 +3,8 @@ syntax = "proto3"; package multieko2.uctovnictvo; +import "adresar.proto"; + service Uctovnictvo { rpc PostUctovnictvo (PostUctovnictvoRequest) returns (UctovnictvoResponse); } diff --git a/src/adresar/handlers/delete_adresar.rs b/src/adresar/handlers/delete_adresar.rs index fa06f40..fc7b616 100644 --- a/src/adresar/handlers/delete_adresar.rs +++ b/src/adresar/handlers/delete_adresar.rs @@ -1,7 +1,7 @@ // src/adresar/handlers/delete_adresar.rs use tonic::Status; use sqlx::PgPool; -use crate::proto::multieko2::{DeleteAdresarRequest, DeleteAdresarResponse}; +use crate::proto::multieko2::adresar::{DeleteAdresarRequest, DeleteAdresarResponse}; pub async fn delete_adresar( db_pool: &PgPool, diff --git a/src/adresar/handlers/get_adresar.rs b/src/adresar/handlers/get_adresar.rs index b20b1f9..13e1996 100644 --- a/src/adresar/handlers/get_adresar.rs +++ b/src/adresar/handlers/get_adresar.rs @@ -2,7 +2,7 @@ use tonic::Status; use sqlx::PgPool; use crate::adresar::models::Adresar; -use crate::proto::multieko2::{GetAdresarRequest, AdresarResponse}; +use crate::proto::multieko2::adresar::{GetAdresarRequest, AdresarResponse}; pub async fn get_adresar( db_pool: &PgPool, diff --git a/src/adresar/handlers/get_adresar_by_position.rs b/src/adresar/handlers/get_adresar_by_position.rs index 9470bc9..2f9c824 100644 --- a/src/adresar/handlers/get_adresar_by_position.rs +++ b/src/adresar/handlers/get_adresar_by_position.rs @@ -1,7 +1,7 @@ // src/adresar/handlers/get_adresar_by_position.rs use tonic::{Status}; use sqlx::PgPool; -use crate::proto::multieko2::{PositionRequest, AdresarResponse, GetAdresarRequest}; +use crate::proto::multieko2::adresar::{PositionRequest, AdresarResponse, GetAdresarRequest}; use super::get_adresar; pub async fn get_adresar_by_position( diff --git a/src/adresar/handlers/get_adresar_count.rs b/src/adresar/handlers/get_adresar_count.rs index dc93c7c..6f11802 100644 --- a/src/adresar/handlers/get_adresar_count.rs +++ b/src/adresar/handlers/get_adresar_count.rs @@ -1,7 +1,7 @@ // src/adresar/handlers/get_adresar_count.rs use tonic::Status; use sqlx::PgPool; -use crate::proto::multieko2::{CountResponse, Empty}; +use crate::proto::multieko2::adresar::{CountResponse, Empty}; pub async fn get_adresar_count( db_pool: &PgPool, diff --git a/src/adresar/handlers/get_table_structure.rs b/src/adresar/handlers/get_table_structure.rs index e1b6cb1..0b98a52 100644 --- a/src/adresar/handlers/get_table_structure.rs +++ b/src/adresar/handlers/get_table_structure.rs @@ -1,7 +1,7 @@ // src/adresar/handlers/get_table_structure.rs use tonic::Status; use sqlx::PgPool; -use crate::proto::multieko2::{TableStructureResponse, TableColumn, Empty}; +use crate::proto::multieko2::adresar::{TableStructureResponse, TableColumn, Empty}; pub async fn get_table_structure( db_pool: &PgPool, diff --git a/src/adresar/handlers/post_adresar.rs b/src/adresar/handlers/post_adresar.rs index f47c608..cb5826b 100644 --- a/src/adresar/handlers/post_adresar.rs +++ b/src/adresar/handlers/post_adresar.rs @@ -2,7 +2,7 @@ use tonic::Status; use sqlx::PgPool; use crate::adresar::models::Adresar; -use crate::proto::multieko2::{PostAdresarRequest, AdresarResponse}; +use crate::proto::multieko2::adresar::{PostAdresarRequest, AdresarResponse}; pub async fn post_adresar( db_pool: &PgPool, diff --git a/src/adresar/handlers/put_adresar.rs b/src/adresar/handlers/put_adresar.rs index 51ca751..c549bd4 100644 --- a/src/adresar/handlers/put_adresar.rs +++ b/src/adresar/handlers/put_adresar.rs @@ -2,7 +2,7 @@ use tonic::Status; use sqlx::PgPool; use crate::adresar::models::Adresar; -use crate::proto::multieko2::{PutAdresarRequest, AdresarResponse}; +use crate::proto::multieko2::adresar::{PutAdresarRequest, AdresarResponse}; pub async fn put_adresar( db_pool: &PgPool, diff --git a/src/proto/descriptor.bin b/src/proto/descriptor.bin index ffe8df8..155655a 100644 Binary files a/src/proto/descriptor.bin and b/src/proto/descriptor.bin differ diff --git a/src/proto/mod.rs b/src/proto/mod.rs index 8f281a7..a76de70 100644 --- a/src/proto/mod.rs +++ b/src/proto/mod.rs @@ -1,10 +1,14 @@ // src/proto/mod.rs pub mod multieko2 { tonic::include_proto!("multieko2"); + + pub mod adresar { + tonic::include_proto!("multieko2.adresar"); + } + pub mod uctovnictvo { tonic::include_proto!("multieko2.uctovnictvo"); } - // Include the file descriptor set pub const FILE_DESCRIPTOR_SET: &[u8] = include_bytes!("descriptor.bin"); } diff --git a/src/server/mod.rs b/src/server/mod.rs index 39776ea..1e4e40d 100644 --- a/src/server/mod.rs +++ b/src/server/mod.rs @@ -6,11 +6,13 @@ use crate::adresar::handlers::{ }; use crate::uctovnictvo::handlers::post_uctovnictvo; use crate::proto::multieko2::{ + FILE_DESCRIPTOR_SET, +}; +use crate::proto::multieko2::adresar::{ + adresar_server::{Adresar, AdresarServer}, PostAdresarRequest, AdresarResponse, GetAdresarRequest, PutAdresarRequest, DeleteAdresarRequest, DeleteAdresarResponse, PositionRequest, CountResponse, Empty, TableStructureResponse, - adresar_server::{Adresar, AdresarServer}, - FILE_DESCRIPTOR_SET, }; use crate::proto::multieko2::uctovnictvo::{ uctovnictvo_server::{Uctovnictvo, UctovnictvoServer},