diff --git a/proto/uctovnictvo.proto b/proto/uctovnictvo.proto index 816a642..af97e17 100644 --- a/proto/uctovnictvo.proto +++ b/proto/uctovnictvo.proto @@ -8,6 +8,7 @@ import "adresar.proto"; service Uctovnictvo { rpc PostUctovnictvo (PostUctovnictvoRequest) returns (UctovnictvoResponse); rpc GetUctovnictvo (GetUctovnictvoRequest) returns (UctovnictvoResponse); + rpc GetUctovnictvoCount (multieko2.adresar.Empty) returns (multieko2.adresar.CountResponse); } message PostUctovnictvoRequest { diff --git a/src/proto/descriptor.bin b/src/proto/descriptor.bin index b5d6e25..d601206 100644 Binary files a/src/proto/descriptor.bin and b/src/proto/descriptor.bin differ diff --git a/src/server/mod.rs b/src/server/mod.rs index 7dc92d2..411628d 100644 --- a/src/server/mod.rs +++ b/src/server/mod.rs @@ -4,7 +4,7 @@ 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 }; -use crate::uctovnictvo::handlers::{post_uctovnictvo, get_uctovnictvo}; // Update this line +use crate::uctovnictvo::handlers::{post_uctovnictvo, get_uctovnictvo, get_uctovnictvo_count}; use crate::proto::multieko2::{ FILE_DESCRIPTOR_SET, }; @@ -104,6 +104,14 @@ impl Uctovnictvo for UctovnictvoService { let response = get_uctovnictvo(&self.db_pool, request.into_inner()).await?; Ok(Response::new(response)) } + + async fn get_uctovnictvo_count( + &self, + request: Request, + ) -> Result, Status> { + let response = get_uctovnictvo_count(&self.db_pool, request.into_inner()).await?; + Ok(Response::new(response)) + } } pub async fn run_server(db_pool: sqlx::PgPool) -> Result<(), Box> { diff --git a/src/uctovnictvo/handlers.rs b/src/uctovnictvo/handlers.rs index 807ed00..b978290 100644 --- a/src/uctovnictvo/handlers.rs +++ b/src/uctovnictvo/handlers.rs @@ -1,7 +1,8 @@ // src/uctovnictvo/handlers.rs - pub mod post_uctovnictvo; -pub mod get_uctovnictvo; // Add this line +pub mod get_uctovnictvo; +pub mod get_uctovnictvo_count; // Add this line pub use post_uctovnictvo::post_uctovnictvo; -pub use get_uctovnictvo::get_uctovnictvo; // Add this line +pub use get_uctovnictvo::get_uctovnictvo; +pub use get_uctovnictvo_count::get_uctovnictvo_count; // Add this line diff --git a/src/uctovnictvo/handlers/get_uctovnictvo_count.rs b/src/uctovnictvo/handlers/get_uctovnictvo_count.rs new file mode 100644 index 0000000..1c72321 --- /dev/null +++ b/src/uctovnictvo/handlers/get_uctovnictvo_count.rs @@ -0,0 +1,23 @@ +// src/uctovnictvo/handlers/get_uctovnictvo_count.rs +use tonic::Status; +use sqlx::PgPool; +use crate::proto::multieko2::adresar::{CountResponse, Empty}; + +pub async fn get_uctovnictvo_count( + db_pool: &PgPool, + _request: Empty, +) -> Result { + let count: i64 = sqlx::query_scalar!( + r#" + SELECT COUNT(*) AS count + FROM uctovnictvo + WHERE deleted = FALSE + "# + ) + .fetch_one(db_pool) + .await + .map_err(|e| Status::internal(e.to_string()))? + .unwrap_or(0); + + Ok(CountResponse { count }) +}