complete redesign
This commit is contained in:
78
server/src/uctovnictvo/handlers/put_uctovnictvo.rs
Normal file
78
server/src/uctovnictvo/handlers/put_uctovnictvo.rs
Normal file
@@ -0,0 +1,78 @@
|
||||
// src/uctovnictvo/handlers/put_uctovnictvo.rs
|
||||
use tonic::Status;
|
||||
use sqlx::PgPool;
|
||||
use crate::uctovnictvo::models::Uctovnictvo;
|
||||
use common::proto::multieko2::uctovnictvo::{PutUctovnictvoRequest, UctovnictvoResponse};
|
||||
use crate::shared::date_utils::parse_date_with_multiple_formats; // Import from shared module
|
||||
|
||||
pub async fn put_uctovnictvo(
|
||||
db_pool: &PgPool,
|
||||
request: PutUctovnictvoRequest,
|
||||
) -> Result<UctovnictvoResponse, Status> {
|
||||
let datum = parse_date_with_multiple_formats(&request.datum)
|
||||
.ok_or_else(|| Status::invalid_argument("Invalid date format"))?;
|
||||
|
||||
let uctovnictvo = sqlx::query_as!(
|
||||
Uctovnictvo,
|
||||
r#"
|
||||
UPDATE uctovnictvo
|
||||
SET
|
||||
adresar_id = $2,
|
||||
c_dokladu = $3,
|
||||
datum = $4,
|
||||
c_faktury = $5,
|
||||
obsah = $6,
|
||||
stredisko = $7,
|
||||
c_uctu = $8,
|
||||
md = $9,
|
||||
identif = $10,
|
||||
poznanka = $11,
|
||||
firma = $12
|
||||
WHERE id = $1 AND deleted = FALSE
|
||||
RETURNING
|
||||
id,
|
||||
deleted,
|
||||
adresar_id,
|
||||
c_dokladu,
|
||||
datum as "datum: chrono::NaiveDate",
|
||||
c_faktury,
|
||||
obsah,
|
||||
stredisko,
|
||||
c_uctu,
|
||||
md,
|
||||
identif,
|
||||
poznanka,
|
||||
firma
|
||||
"#,
|
||||
request.id,
|
||||
request.adresar_id,
|
||||
request.c_dokladu,
|
||||
datum as chrono::NaiveDate,
|
||||
request.c_faktury,
|
||||
request.obsah,
|
||||
request.stredisko,
|
||||
request.c_uctu,
|
||||
request.md,
|
||||
request.identif,
|
||||
request.poznanka,
|
||||
request.firma
|
||||
)
|
||||
.fetch_one(db_pool)
|
||||
.await
|
||||
.map_err(|e| Status::internal(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