working finally
This commit is contained in:
@@ -8,7 +8,7 @@ use crate::uctovnictvo::handlers::post_uctovnictvo;
|
|||||||
use crate::proto::multieko2::{
|
use crate::proto::multieko2::{
|
||||||
PostAdresarRequest, AdresarResponse, GetAdresarRequest, PutAdresarRequest,
|
PostAdresarRequest, AdresarResponse, GetAdresarRequest, PutAdresarRequest,
|
||||||
DeleteAdresarRequest, DeleteAdresarResponse, PositionRequest, CountResponse, Empty,
|
DeleteAdresarRequest, DeleteAdresarResponse, PositionRequest, CountResponse, Empty,
|
||||||
TableStructureResponse, PostUctovnictvoRequest, UctovnictvoResponse,
|
TableStructureResponse,
|
||||||
adresar_server::{Adresar, AdresarServer},
|
adresar_server::{Adresar, AdresarServer},
|
||||||
FILE_DESCRIPTOR_SET,
|
FILE_DESCRIPTOR_SET,
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
// src/uctovnictvo/handlers/post_uctovnictvo.rs
|
// src/uctovnictvo/handlers/post_uctovnictvo.rs
|
||||||
use tonic::Status;
|
use tonic::Status;
|
||||||
use sqlx::PgPool;
|
use sqlx::PgPool;
|
||||||
use chrono::NaiveDate;
|
use chrono::NaiveDate; // Using chrono directly!
|
||||||
use crate::uctovnictvo::models::Uctovnictvo;
|
use crate::uctovnictvo::models::Uctovnictvo;
|
||||||
use crate::proto::multieko2::uctovnictvo::{PostUctovnictvoRequest, UctovnictvoResponse};
|
use crate::proto::multieko2::uctovnictvo::{PostUctovnictvoRequest, UctovnictvoResponse};
|
||||||
|
|
||||||
@@ -9,10 +9,11 @@ pub async fn post_uctovnictvo(
|
|||||||
db_pool: &PgPool,
|
db_pool: &PgPool,
|
||||||
request: PostUctovnictvoRequest,
|
request: PostUctovnictvoRequest,
|
||||||
) -> Result<UctovnictvoResponse, Status> {
|
) -> Result<UctovnictvoResponse, Status> {
|
||||||
// Parse the date string into NaiveDate
|
// Parse the date string into a chrono::NaiveDate.
|
||||||
let datum = chrono::NaiveDate::parse_from_str(&request.datum, "%Y-%m-%d")
|
let datum = NaiveDate::parse_from_str(&request.datum, "%Y-%m-%d")
|
||||||
.map_err(|e| Status::invalid_argument(format!("Invalid date: {}", e)))?;
|
.map_err(|e| Status::invalid_argument(format!("Invalid date: {}", e)))?;
|
||||||
|
|
||||||
|
// Pass the NaiveDate value directly.
|
||||||
let uctovnictvo = sqlx::query_as!(
|
let uctovnictvo = sqlx::query_as!(
|
||||||
Uctovnictvo,
|
Uctovnictvo,
|
||||||
r#"
|
r#"
|
||||||
@@ -24,12 +25,23 @@ pub async fn post_uctovnictvo(
|
|||||||
$1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12
|
$1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12
|
||||||
)
|
)
|
||||||
RETURNING
|
RETURNING
|
||||||
id, deleted, adresar_id, c_dokladu, datum, c_faktury, obsah,
|
id,
|
||||||
stredisko, c_uctu, md, identif, poznanka, firma
|
deleted,
|
||||||
|
adresar_id,
|
||||||
|
c_dokladu,
|
||||||
|
datum as "datum: chrono::NaiveDate",
|
||||||
|
c_faktury,
|
||||||
|
obsah,
|
||||||
|
stredisko,
|
||||||
|
c_uctu,
|
||||||
|
md,
|
||||||
|
identif,
|
||||||
|
poznanka,
|
||||||
|
firma
|
||||||
"#,
|
"#,
|
||||||
request.adresar_id,
|
request.adresar_id,
|
||||||
request.c_dokladu,
|
request.c_dokladu,
|
||||||
datum,
|
datum as chrono::NaiveDate,
|
||||||
request.c_faktury,
|
request.c_faktury,
|
||||||
request.obsah,
|
request.obsah,
|
||||||
request.stredisko,
|
request.stredisko,
|
||||||
@@ -38,17 +50,19 @@ pub async fn post_uctovnictvo(
|
|||||||
request.identif,
|
request.identif,
|
||||||
request.poznanka,
|
request.poznanka,
|
||||||
request.firma,
|
request.firma,
|
||||||
false // Set deleted to false by default
|
false
|
||||||
)
|
)
|
||||||
.fetch_one(db_pool)
|
.fetch_one(db_pool)
|
||||||
.await
|
.await
|
||||||
.map_err(|e| Status::internal(e.to_string()))?;
|
.map_err(|e| Status::internal(e.to_string()))?;
|
||||||
|
|
||||||
|
// Convert the NaiveDate back to a String for the API response,
|
||||||
|
// if that format fits your client requirements.
|
||||||
Ok(UctovnictvoResponse {
|
Ok(UctovnictvoResponse {
|
||||||
id: uctovnictvo.id,
|
id: uctovnictvo.id,
|
||||||
adresar_id: uctovnictvo.adresar_id,
|
adresar_id: uctovnictvo.adresar_id,
|
||||||
c_dokladu: uctovnictvo.c_dokladu,
|
c_dokladu: uctovnictvo.c_dokladu,
|
||||||
datum: uctovnictvo.datum.to_string(), // Convert NaiveDate back to string
|
datum: uctovnictvo.datum.to_string(),
|
||||||
c_faktury: uctovnictvo.c_faktury,
|
c_faktury: uctovnictvo.c_faktury,
|
||||||
obsah: uctovnictvo.obsah.unwrap_or_default(),
|
obsah: uctovnictvo.obsah.unwrap_or_default(),
|
||||||
stredisko: uctovnictvo.stredisko.unwrap_or_default(),
|
stredisko: uctovnictvo.stredisko.unwrap_or_default(),
|
||||||
@@ -59,3 +73,4 @@ pub async fn post_uctovnictvo(
|
|||||||
firma: uctovnictvo.firma,
|
firma: uctovnictvo.firma,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ pub struct Uctovnictvo {
|
|||||||
pub deleted: bool,
|
pub deleted: bool,
|
||||||
pub adresar_id: i64,
|
pub adresar_id: i64,
|
||||||
pub c_dokladu: String,
|
pub c_dokladu: String,
|
||||||
pub datum: chrono::NaiveDate,
|
pub datum: NaiveDate,
|
||||||
pub c_faktury: String,
|
pub c_faktury: String,
|
||||||
pub obsah: Option<String>,
|
pub obsah: Option<String>,
|
||||||
pub stredisko: Option<String>,
|
pub stredisko: Option<String>,
|
||||||
@@ -18,3 +18,4 @@ pub struct Uctovnictvo {
|
|||||||
pub poznanka: Option<String>,
|
pub poznanka: Option<String>,
|
||||||
pub firma: String,
|
pub firma: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user