working get request
This commit is contained in:
@@ -7,6 +7,7 @@ import "adresar.proto";
|
||||
|
||||
service Uctovnictvo {
|
||||
rpc PostUctovnictvo (PostUctovnictvoRequest) returns (UctovnictvoResponse);
|
||||
rpc GetUctovnictvo (GetUctovnictvoRequest) returns (UctovnictvoResponse);
|
||||
}
|
||||
|
||||
message PostUctovnictvoRequest {
|
||||
@@ -37,3 +38,7 @@ message UctovnictvoResponse {
|
||||
string poznanka = 11;
|
||||
string firma = 12;
|
||||
}
|
||||
|
||||
message GetUctovnictvoRequest {
|
||||
int64 id = 1;
|
||||
}
|
||||
|
||||
Binary file not shown.
@@ -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;
|
||||
use crate::uctovnictvo::handlers::{post_uctovnictvo, get_uctovnictvo}; // Update this line
|
||||
use crate::proto::multieko2::{
|
||||
FILE_DESCRIPTOR_SET,
|
||||
};
|
||||
@@ -16,7 +16,7 @@ use crate::proto::multieko2::adresar::{
|
||||
};
|
||||
use crate::proto::multieko2::uctovnictvo::{
|
||||
uctovnictvo_server::{Uctovnictvo, UctovnictvoServer},
|
||||
PostUctovnictvoRequest, UctovnictvoResponse
|
||||
PostUctovnictvoRequest, UctovnictvoResponse, GetUctovnictvoRequest // Add this import
|
||||
};
|
||||
|
||||
pub struct AdresarService {
|
||||
@@ -95,6 +95,15 @@ impl Uctovnictvo for UctovnictvoService {
|
||||
let response = post_uctovnictvo(&self.db_pool, request.into_inner()).await?;
|
||||
Ok(Response::new(response))
|
||||
}
|
||||
|
||||
// Add this method
|
||||
async fn get_uctovnictvo(
|
||||
&self,
|
||||
request: Request<GetUctovnictvoRequest>,
|
||||
) -> Result<Response<UctovnictvoResponse>, Status> {
|
||||
let response = get_uctovnictvo(&self.db_pool, request.into_inner()).await?;
|
||||
Ok(Response::new(response))
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn run_server(db_pool: sqlx::PgPool) -> Result<(), Box<dyn std::error::Error>> {
|
||||
|
||||
17
src/uctovnictvo/docs/get_examples.txt
Normal file
17
src/uctovnictvo/docs/get_examples.txt
Normal file
@@ -0,0 +1,17 @@
|
||||
❯ grpcurl -plaintext -d '{
|
||||
"id": 1
|
||||
}' localhost:50051 multieko2.uctovnictvo.Uctovnictvo/GetUctovnictvo
|
||||
{
|
||||
"id": "1",
|
||||
"adresarId": "1",
|
||||
"cDokladu": "DOC123",
|
||||
"datum": "01.10.2023",
|
||||
"cFaktury": "INV123",
|
||||
"obsah": "Sample content",
|
||||
"stredisko": "Center A",
|
||||
"cUctu": "ACC123",
|
||||
"md": "MD123",
|
||||
"identif": "ID123",
|
||||
"poznanka": "Sample note",
|
||||
"firma": "AAA"
|
||||
}
|
||||
@@ -1,5 +1,7 @@
|
||||
// src/uctovnictvo/handlers.rs
|
||||
|
||||
pub mod post_uctovnictvo;
|
||||
pub mod get_uctovnictvo; // Add this line
|
||||
|
||||
pub use post_uctovnictvo::post_uctovnictvo;
|
||||
pub use get_uctovnictvo::get_uctovnictvo; // Add this line
|
||||
|
||||
51
src/uctovnictvo/handlers/get_uctovnictvo.rs
Normal file
51
src/uctovnictvo/handlers/get_uctovnictvo.rs
Normal file
@@ -0,0 +1,51 @@
|
||||
// src/uctovnictvo/handlers/get_uctovnictvo.rs
|
||||
use tonic::Status;
|
||||
use sqlx::PgPool;
|
||||
use crate::uctovnictvo::models::Uctovnictvo;
|
||||
use crate::proto::multieko2::uctovnictvo::{GetUctovnictvoRequest, UctovnictvoResponse};
|
||||
|
||||
pub async fn get_uctovnictvo(
|
||||
db_pool: &PgPool,
|
||||
request: GetUctovnictvoRequest,
|
||||
) -> Result<UctovnictvoResponse, Status> {
|
||||
let uctovnictvo = sqlx::query_as!(
|
||||
Uctovnictvo,
|
||||
r#"
|
||||
SELECT
|
||||
id,
|
||||
deleted,
|
||||
adresar_id,
|
||||
c_dokladu,
|
||||
datum as "datum: chrono::NaiveDate",
|
||||
c_faktury,
|
||||
obsah,
|
||||
stredisko,
|
||||
c_uctu,
|
||||
md,
|
||||
identif,
|
||||
poznanka,
|
||||
firma
|
||||
FROM uctovnictvo
|
||||
WHERE id = $1
|
||||
"#,
|
||||
request.id
|
||||
)
|
||||
.fetch_one(db_pool)
|
||||
.await
|
||||
.map_err(|e| Status::not_found(e.to_string()))?;
|
||||
|
||||
Ok(UctovnictvoResponse {
|
||||
id: uctovnictvo.id,
|
||||
adresar_id: uctovnictvo.adresar_id,
|
||||
c_dokladu: uctovnictvo.c_dokladu,
|
||||
datum: uctovnictvo.datum.format("%d.%m.%Y").to_string(),
|
||||
c_faktury: uctovnictvo.c_faktury,
|
||||
obsah: uctovnictvo.obsah.unwrap_or_default(),
|
||||
stredisko: uctovnictvo.stredisko.unwrap_or_default(),
|
||||
c_uctu: uctovnictvo.c_uctu.unwrap_or_default(),
|
||||
md: uctovnictvo.md.unwrap_or_default(),
|
||||
identif: uctovnictvo.identif.unwrap_or_default(),
|
||||
poznanka: uctovnictvo.poznanka.unwrap_or_default(),
|
||||
firma: uctovnictvo.firma,
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user