removing adresar and uctovnictvo hardcoded way of doing things from the project entirely
This commit is contained in:
@@ -1,156 +0,0 @@
|
|||||||
❯ grpcurl -plaintext -d '{"id": 1}' localhost:50051 multieko2.adresar.Adresar/GetAdresar
|
|
||||||
{
|
|
||||||
"id": "1",
|
|
||||||
"firma": "Updated Firma",
|
|
||||||
"kz": "Updated KZ",
|
|
||||||
"drc": "Updated DRC",
|
|
||||||
"ulica": "Updated Ulica",
|
|
||||||
"psc": "Updated PSC",
|
|
||||||
"mesto": "Updated Mesto",
|
|
||||||
"stat": "Updated Stat",
|
|
||||||
"banka": "Updated Banka",
|
|
||||||
"ucet": "Updated Ucet",
|
|
||||||
"skladm": "Updated Skladm",
|
|
||||||
"ico": "Updated ICO",
|
|
||||||
"kontakt": "Updated Kontakt",
|
|
||||||
"telefon": "Updated Telefon",
|
|
||||||
"skladu": "Updated Skladu",
|
|
||||||
"fax": "Updated Fax"
|
|
||||||
}
|
|
||||||
❯ grpcurl -plaintext -d '{"id": 2}' localhost:50051 multieko2.adresar.Adresar/GetAdresar
|
|
||||||
{
|
|
||||||
"id": "2",
|
|
||||||
"firma": "asdfasf",
|
|
||||||
"kz": " ",
|
|
||||||
"drc": " ",
|
|
||||||
"ulica": " ",
|
|
||||||
"psc": "sdfasdf",
|
|
||||||
"mesto": "asf",
|
|
||||||
"stat": "as",
|
|
||||||
"banka": "df",
|
|
||||||
"ucet": "asf",
|
|
||||||
"skladm": "f",
|
|
||||||
"ico": "f",
|
|
||||||
"kontakt": "f",
|
|
||||||
"telefon": "f",
|
|
||||||
"skladu": "f",
|
|
||||||
"fax": " "
|
|
||||||
}
|
|
||||||
❯ grpcurl -plaintext -d '{"id": 1}' localhost:50051 multieko2.adresar.Adresar/DeleteAdresar
|
|
||||||
{
|
|
||||||
"success": true
|
|
||||||
}
|
|
||||||
❯ grpcurl -plaintext -d '{"id": 1}' localhost:50051 multieko2.adresar.Adresar/GetAdresar
|
|
||||||
ERROR:
|
|
||||||
Code: NotFound
|
|
||||||
Message: no rows returned by a query that expected to return at least one row
|
|
||||||
❯ grpcurl -plaintext -d '{"id": 2}' localhost:50051 multieko2.adresar.Adresar/GetAdresar
|
|
||||||
{
|
|
||||||
"id": "2",
|
|
||||||
"firma": "asdfasf",
|
|
||||||
"kz": " ",
|
|
||||||
"drc": " ",
|
|
||||||
"ulica": " ",
|
|
||||||
"psc": "sdfasdf",
|
|
||||||
"mesto": "asf",
|
|
||||||
"stat": "as",
|
|
||||||
"banka": "df",
|
|
||||||
"ucet": "asf",
|
|
||||||
"skladm": "f",
|
|
||||||
"ico": "f",
|
|
||||||
"kontakt": "f",
|
|
||||||
"telefon": "f",
|
|
||||||
"skladu": "f",
|
|
||||||
"fax": " "
|
|
||||||
}
|
|
||||||
|
|
||||||
❯ grpcurl -plaintext -d '{
|
|
||||||
"firma": "New Firma",
|
|
||||||
"kz": "New KZ",
|
|
||||||
"drc": "New DRC",
|
|
||||||
"ulica": "New Ulica",
|
|
||||||
"psc": "New PSC",
|
|
||||||
"mesto": "New Mesto",
|
|
||||||
"stat": "New Stat",
|
|
||||||
"banka": "New Banka",
|
|
||||||
"ucet": "New Ucet",
|
|
||||||
"skladm": "New Skladm",
|
|
||||||
"ico": "New ICO",
|
|
||||||
"kontakt": "New Kontakt",
|
|
||||||
"telefon": "New Telefon",
|
|
||||||
"skladu": "New Skladu",
|
|
||||||
"fax": "New Fax"
|
|
||||||
}' localhost:50051 multieko2.adresar.Adresar/PostAdresar
|
|
||||||
{
|
|
||||||
"id": "43",
|
|
||||||
"firma": "New Firma",
|
|
||||||
"kz": "New KZ",
|
|
||||||
"drc": "New DRC",
|
|
||||||
"ulica": "New Ulica",
|
|
||||||
"psc": "New PSC",
|
|
||||||
"mesto": "New Mesto",
|
|
||||||
"stat": "New Stat",
|
|
||||||
"banka": "New Banka",
|
|
||||||
"ucet": "New Ucet",
|
|
||||||
"skladm": "New Skladm",
|
|
||||||
"ico": "New ICO",
|
|
||||||
"kontakt": "New Kontakt",
|
|
||||||
"telefon": "New Telefon",
|
|
||||||
"skladu": "New Skladu",
|
|
||||||
"fax": "New Fax"
|
|
||||||
}
|
|
||||||
❯ grpcurl -plaintext -d '{
|
|
||||||
"id": 43,
|
|
||||||
"firma": "Updated Firma",
|
|
||||||
"kz": "Updated KZ",
|
|
||||||
"drc": "Updated DRC",
|
|
||||||
"ulica": "Updated Ulica",
|
|
||||||
"psc": "Updated PSC",
|
|
||||||
"mesto": "Updated Mesto",
|
|
||||||
"stat": "Updated Stat",
|
|
||||||
"banka": "Updated Banka",
|
|
||||||
"ucet": "Updated Ucet",
|
|
||||||
"skladm": "Updated Skladm",
|
|
||||||
"ico": "Updated ICO",
|
|
||||||
"kontakt": "Updated Kontakt",
|
|
||||||
"telefon": "Updated Telefon",
|
|
||||||
"skladu": "Updated Skladu",
|
|
||||||
"fax": "Updated Fax"
|
|
||||||
}' localhost:50051 multieko2.adresar.Adresar/PutAdresar
|
|
||||||
{
|
|
||||||
"id": "43",
|
|
||||||
"firma": "Updated Firma",
|
|
||||||
"kz": "Updated KZ",
|
|
||||||
"drc": "Updated DRC",
|
|
||||||
"ulica": "Updated Ulica",
|
|
||||||
"psc": "Updated PSC",
|
|
||||||
"mesto": "Updated Mesto",
|
|
||||||
"stat": "Updated Stat",
|
|
||||||
"banka": "Updated Banka",
|
|
||||||
"ucet": "Updated Ucet",
|
|
||||||
"skladm": "Updated Skladm",
|
|
||||||
"ico": "Updated ICO",
|
|
||||||
"kontakt": "Updated Kontakt",
|
|
||||||
"telefon": "Updated Telefon",
|
|
||||||
"skladu": "Updated Skladu",
|
|
||||||
"fax": "Updated Fax"
|
|
||||||
}
|
|
||||||
❯ grpcurl -plaintext -d '{"id": 43}' localhost:50051 multieko2.adresar.Adresar/GetAdresar
|
|
||||||
{
|
|
||||||
"id": "43",
|
|
||||||
"firma": "Updated Firma",
|
|
||||||
"kz": "Updated KZ",
|
|
||||||
"drc": "Updated DRC",
|
|
||||||
"ulica": "Updated Ulica",
|
|
||||||
"psc": "Updated PSC",
|
|
||||||
"mesto": "Updated Mesto",
|
|
||||||
"stat": "Updated Stat",
|
|
||||||
"banka": "Updated Banka",
|
|
||||||
"ucet": "Updated Ucet",
|
|
||||||
"skladm": "Updated Skladm",
|
|
||||||
"ico": "Updated ICO",
|
|
||||||
"kontakt": "Updated Kontakt",
|
|
||||||
"telefon": "Updated Telefon",
|
|
||||||
"skladu": "Updated Skladu",
|
|
||||||
"fax": "Updated Fax"
|
|
||||||
}
|
|
||||||
@@ -1,29 +0,0 @@
|
|||||||
|
|
||||||
# TOTAL items in the adresar
|
|
||||||
❯ grpcurl -plaintext localhost:50051 multieko2.adresar.Adresar/GetAdresarCount
|
|
||||||
{
|
|
||||||
"count": "5"
|
|
||||||
}
|
|
||||||
# Item at this count. If there are 43 items, number 1 is the first item
|
|
||||||
❯ grpcurl -plaintext -d '{"position": 1}' localhost:50051 multieko2.adresar.Adresar/GetAdresarByPosition
|
|
||||||
{
|
|
||||||
"id": "1",
|
|
||||||
"firma": "ks555",
|
|
||||||
"kz": "f",
|
|
||||||
"drc": "asdf",
|
|
||||||
"ulica": "as",
|
|
||||||
"psc": "f",
|
|
||||||
"mesto": "asf",
|
|
||||||
"stat": "as",
|
|
||||||
"banka": "fa",
|
|
||||||
"telefon": "a",
|
|
||||||
"skladu": "fd",
|
|
||||||
"fax": "asf"
|
|
||||||
}
|
|
||||||
# Item fetched by id. The first item was created and marked as deleted, therefore number 1 in ids shouldnt be fetched.
|
|
||||||
❯ grpcurl -plaintext -d '{"id": 1}' localhost:50051 multieko2.adresar.Adresar/GetAdresar
|
|
||||||
ERROR:
|
|
||||||
Code: NotFound
|
|
||||||
Message: no rows returned by a query that expected to return at least one row
|
|
||||||
╭─ ~ ············································· 69 ✘
|
|
||||||
╰─
|
|
||||||
@@ -1,15 +0,0 @@
|
|||||||
// src/adresar/handlers.rs
|
|
||||||
|
|
||||||
pub mod post_adresar;
|
|
||||||
pub mod get_adresar;
|
|
||||||
pub mod put_adresar;
|
|
||||||
pub mod delete_adresar;
|
|
||||||
pub mod get_adresar_count;
|
|
||||||
pub mod get_adresar_by_position;
|
|
||||||
|
|
||||||
pub use post_adresar::post_adresar;
|
|
||||||
pub use get_adresar::get_adresar;
|
|
||||||
pub use put_adresar::put_adresar;
|
|
||||||
pub use delete_adresar::delete_adresar;
|
|
||||||
pub use get_adresar_count::get_adresar_count;
|
|
||||||
pub use get_adresar_by_position::get_adresar_by_position;
|
|
||||||
@@ -1,27 +0,0 @@
|
|||||||
// src/adresar/handlers/delete_adresar.rs
|
|
||||||
use tonic::Status;
|
|
||||||
use sqlx::PgPool;
|
|
||||||
use common::proto::multieko2::adresar::{DeleteAdresarRequest, DeleteAdresarResponse};
|
|
||||||
|
|
||||||
pub async fn delete_adresar(
|
|
||||||
db_pool: &PgPool,
|
|
||||||
request: DeleteAdresarRequest,
|
|
||||||
) -> Result<DeleteAdresarResponse, Status> {
|
|
||||||
let rows_affected = sqlx::query!(
|
|
||||||
r#"
|
|
||||||
UPDATE adresar
|
|
||||||
SET deleted = true
|
|
||||||
WHERE id = $1 AND deleted = false
|
|
||||||
"#,
|
|
||||||
request.id
|
|
||||||
)
|
|
||||||
.execute(db_pool)
|
|
||||||
.await
|
|
||||||
.map_err(|e| Status::internal(e.to_string()))?
|
|
||||||
.rows_affected();
|
|
||||||
|
|
||||||
Ok(DeleteAdresarResponse {
|
|
||||||
success: rows_affected > 0,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
@@ -1,63 +0,0 @@
|
|||||||
// src/adresar/handlers/get_adresar.rs
|
|
||||||
use tonic::Status;
|
|
||||||
use sqlx::PgPool;
|
|
||||||
use crate::adresar::models::Adresar;
|
|
||||||
use common::proto::multieko2::adresar::{GetAdresarRequest, AdresarResponse};
|
|
||||||
|
|
||||||
pub async fn get_adresar(
|
|
||||||
db_pool: &PgPool,
|
|
||||||
request: GetAdresarRequest,
|
|
||||||
) -> Result<AdresarResponse, Status> {
|
|
||||||
let adresar = sqlx::query_as!(
|
|
||||||
Adresar,
|
|
||||||
r#"
|
|
||||||
SELECT
|
|
||||||
id,
|
|
||||||
deleted,
|
|
||||||
firma,
|
|
||||||
kz,
|
|
||||||
drc,
|
|
||||||
ulica,
|
|
||||||
psc,
|
|
||||||
mesto,
|
|
||||||
stat,
|
|
||||||
banka,
|
|
||||||
ucet,
|
|
||||||
skladm,
|
|
||||||
ico,
|
|
||||||
kontakt,
|
|
||||||
telefon,
|
|
||||||
skladu,
|
|
||||||
fax
|
|
||||||
FROM adresar
|
|
||||||
WHERE id = $1 AND deleted = false
|
|
||||||
"#,
|
|
||||||
request.id
|
|
||||||
)
|
|
||||||
.fetch_one(db_pool)
|
|
||||||
.await
|
|
||||||
.map_err(|e| match e {
|
|
||||||
sqlx::Error::RowNotFound => Status::not_found("Record not found"),
|
|
||||||
_ => Status::internal(format!("Database error: {}", e)),
|
|
||||||
})?;
|
|
||||||
|
|
||||||
Ok(AdresarResponse {
|
|
||||||
id: adresar.id,
|
|
||||||
firma: adresar.firma,
|
|
||||||
kz: adresar.kz.unwrap_or_default(),
|
|
||||||
drc: adresar.drc.unwrap_or_default(),
|
|
||||||
ulica: adresar.ulica.unwrap_or_default(),
|
|
||||||
psc: adresar.psc.unwrap_or_default(),
|
|
||||||
mesto: adresar.mesto.unwrap_or_default(),
|
|
||||||
stat: adresar.stat.unwrap_or_default(),
|
|
||||||
banka: adresar.banka.unwrap_or_default(),
|
|
||||||
ucet: adresar.ucet.unwrap_or_default(),
|
|
||||||
skladm: adresar.skladm.unwrap_or_default(),
|
|
||||||
ico: adresar.ico.unwrap_or_default(),
|
|
||||||
kontakt: adresar.kontakt.unwrap_or_default(),
|
|
||||||
telefon: adresar.telefon.unwrap_or_default(),
|
|
||||||
skladu: adresar.skladu.unwrap_or_default(),
|
|
||||||
fax: adresar.fax.unwrap_or_default(),
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
@@ -1,35 +0,0 @@
|
|||||||
// src/adresar/handlers/get_adresar_by_position.rs
|
|
||||||
use tonic::{Status};
|
|
||||||
use sqlx::PgPool;
|
|
||||||
use common::proto::multieko2::adresar::{AdresarResponse, GetAdresarRequest};
|
|
||||||
use common::proto::multieko2::common::PositionRequest;
|
|
||||||
use super::get_adresar;
|
|
||||||
|
|
||||||
pub async fn get_adresar_by_position(
|
|
||||||
db_pool: &PgPool,
|
|
||||||
request: PositionRequest,
|
|
||||||
) -> Result<AdresarResponse, Status> {
|
|
||||||
if request.position < 1 {
|
|
||||||
return Err(Status::invalid_argument("Position must be at least 1"));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Find the ID of the Nth non-deleted record
|
|
||||||
let id: i64 = sqlx::query_scalar!(
|
|
||||||
r#"
|
|
||||||
SELECT id
|
|
||||||
FROM adresar
|
|
||||||
WHERE deleted = FALSE
|
|
||||||
ORDER BY id ASC
|
|
||||||
OFFSET $1
|
|
||||||
LIMIT 1
|
|
||||||
"#,
|
|
||||||
request.position - 1
|
|
||||||
)
|
|
||||||
.fetch_optional(db_pool)
|
|
||||||
.await
|
|
||||||
.map_err(|e| Status::internal(e.to_string()))?
|
|
||||||
.ok_or_else(|| Status::not_found("Position out of bounds"))?;
|
|
||||||
|
|
||||||
// Now fetch the complete record using the existing get_adresar function
|
|
||||||
get_adresar(db_pool, GetAdresarRequest { id }).await
|
|
||||||
}
|
|
||||||
@@ -1,23 +0,0 @@
|
|||||||
// src/adresar/handlers/get_adresar_count.rs
|
|
||||||
use tonic::Status;
|
|
||||||
use sqlx::PgPool;
|
|
||||||
use common::proto::multieko2::common::{CountResponse, Empty};
|
|
||||||
|
|
||||||
pub async fn get_adresar_count(
|
|
||||||
db_pool: &PgPool,
|
|
||||||
_request: Empty,
|
|
||||||
) -> Result<CountResponse, Status> {
|
|
||||||
let count: i64 = sqlx::query_scalar!(
|
|
||||||
r#"
|
|
||||||
SELECT COUNT(*) AS count
|
|
||||||
FROM adresar
|
|
||||||
WHERE deleted = FALSE
|
|
||||||
"#
|
|
||||||
)
|
|
||||||
.fetch_one(db_pool)
|
|
||||||
.await
|
|
||||||
.map_err(|e| Status::internal(e.to_string()))?
|
|
||||||
.unwrap_or(0);
|
|
||||||
|
|
||||||
Ok(CountResponse { count })
|
|
||||||
}
|
|
||||||
@@ -1,99 +0,0 @@
|
|||||||
// src/adresar/handlers/post_adresar.rs
|
|
||||||
use tonic::Status;
|
|
||||||
use sqlx::PgPool;
|
|
||||||
use crate::adresar::models::Adresar;
|
|
||||||
use common::proto::multieko2::adresar::{PostAdresarRequest, AdresarResponse};
|
|
||||||
|
|
||||||
// Helper function to sanitize inputs
|
|
||||||
fn sanitize_input(input: &str) -> Option<String> {
|
|
||||||
let trimmed = input.trim().to_string();
|
|
||||||
if trimmed.is_empty() {
|
|
||||||
None
|
|
||||||
} else {
|
|
||||||
Some(trimmed)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn post_adresar(
|
|
||||||
db_pool: &PgPool,
|
|
||||||
mut request: PostAdresarRequest,
|
|
||||||
) -> Result<AdresarResponse, Status> {
|
|
||||||
request.firma = request.firma.trim().to_string();
|
|
||||||
if request.firma.is_empty() {
|
|
||||||
return Err(Status::invalid_argument("Firma je povinne pole"));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Sanitize optional fields
|
|
||||||
let kz = sanitize_input(&request.kz);
|
|
||||||
let drc = sanitize_input(&request.drc);
|
|
||||||
let ulica = sanitize_input(&request.ulica);
|
|
||||||
let psc = sanitize_input(&request.psc);
|
|
||||||
let mesto = sanitize_input(&request.mesto);
|
|
||||||
let stat = sanitize_input(&request.stat);
|
|
||||||
let banka = sanitize_input(&request.banka);
|
|
||||||
let ucet = sanitize_input(&request.ucet);
|
|
||||||
let skladm = sanitize_input(&request.skladm);
|
|
||||||
let ico = sanitize_input(&request.ico);
|
|
||||||
let kontakt = sanitize_input(&request.kontakt);
|
|
||||||
let telefon = sanitize_input(&request.telefon);
|
|
||||||
let skladu = sanitize_input(&request.skladu);
|
|
||||||
let fax = sanitize_input(&request.fax);
|
|
||||||
|
|
||||||
let adresar = sqlx::query_as!(
|
|
||||||
Adresar,
|
|
||||||
r#"
|
|
||||||
INSERT INTO adresar (
|
|
||||||
firma, kz, drc, ulica, psc, mesto, stat, banka, ucet,
|
|
||||||
skladm, ico, kontakt, telefon, skladu, fax, deleted
|
|
||||||
)
|
|
||||||
VALUES (
|
|
||||||
$1, $2, $3, $4, $5, $6, $7, $8, $9,
|
|
||||||
$10, $11, $12, $13, $14, $15, $16
|
|
||||||
)
|
|
||||||
RETURNING
|
|
||||||
id, deleted, firma, kz, drc, ulica, psc, mesto, stat,
|
|
||||||
banka, ucet, skladm, ico, kontakt, telefon, skladu, fax
|
|
||||||
"#,
|
|
||||||
request.firma,
|
|
||||||
kz,
|
|
||||||
drc,
|
|
||||||
ulica,
|
|
||||||
psc,
|
|
||||||
mesto,
|
|
||||||
stat,
|
|
||||||
banka,
|
|
||||||
ucet,
|
|
||||||
skladm,
|
|
||||||
ico,
|
|
||||||
kontakt,
|
|
||||||
telefon,
|
|
||||||
skladu,
|
|
||||||
fax,
|
|
||||||
false
|
|
||||||
)
|
|
||||||
.fetch_one(db_pool)
|
|
||||||
.await
|
|
||||||
.map_err(|e| Status::internal(e.to_string()))?;
|
|
||||||
|
|
||||||
Ok(AdresarResponse {
|
|
||||||
id: adresar.id,
|
|
||||||
// Do not include `deleted` in the response since it's not
|
|
||||||
// defined in the proto message.
|
|
||||||
firma: adresar.firma,
|
|
||||||
kz: adresar.kz.unwrap_or_default(),
|
|
||||||
drc: adresar.drc.unwrap_or_default(),
|
|
||||||
ulica: adresar.ulica.unwrap_or_default(),
|
|
||||||
psc: adresar.psc.unwrap_or_default(),
|
|
||||||
mesto: adresar.mesto.unwrap_or_default(),
|
|
||||||
stat: adresar.stat.unwrap_or_default(),
|
|
||||||
banka: adresar.banka.unwrap_or_default(),
|
|
||||||
ucet: adresar.ucet.unwrap_or_default(),
|
|
||||||
skladm: adresar.skladm.unwrap_or_default(),
|
|
||||||
ico: adresar.ico.unwrap_or_default(),
|
|
||||||
kontakt: adresar.kontakt.unwrap_or_default(),
|
|
||||||
telefon: adresar.telefon.unwrap_or_default(),
|
|
||||||
skladu: adresar.skladu.unwrap_or_default(),
|
|
||||||
fax: adresar.fax.unwrap_or_default(),
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
@@ -1,122 +0,0 @@
|
|||||||
// src/adresar/handlers/put_adresar.rs
|
|
||||||
use tonic::Status;
|
|
||||||
use sqlx::PgPool;
|
|
||||||
use crate::adresar::models::Adresar;
|
|
||||||
use common::proto::multieko2::adresar::{PutAdresarRequest, AdresarResponse};
|
|
||||||
|
|
||||||
// Add the same sanitize_input helper as in POST handler
|
|
||||||
fn sanitize_input(input: &str) -> Option<String> {
|
|
||||||
let trimmed = input.trim().to_string();
|
|
||||||
if trimmed.is_empty() {
|
|
||||||
None
|
|
||||||
} else {
|
|
||||||
Some(trimmed)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn put_adresar(
|
|
||||||
db_pool: &PgPool,
|
|
||||||
mut request: PutAdresarRequest,
|
|
||||||
) -> Result<AdresarResponse, Status> {
|
|
||||||
// Add validation for required fields like in POST
|
|
||||||
request.firma = request.firma.trim().to_string();
|
|
||||||
if request.firma.is_empty() {
|
|
||||||
return Err(Status::invalid_argument("Firma je povinne pole"));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Sanitize optional fields like in POST
|
|
||||||
let kz = sanitize_input(&request.kz);
|
|
||||||
let drc = sanitize_input(&request.drc);
|
|
||||||
let ulica = sanitize_input(&request.ulica);
|
|
||||||
let psc = sanitize_input(&request.psc);
|
|
||||||
let mesto = sanitize_input(&request.mesto);
|
|
||||||
let stat = sanitize_input(&request.stat);
|
|
||||||
let banka = sanitize_input(&request.banka);
|
|
||||||
let ucet = sanitize_input(&request.ucet);
|
|
||||||
let skladm = sanitize_input(&request.skladm);
|
|
||||||
let ico = sanitize_input(&request.ico);
|
|
||||||
let kontakt = sanitize_input(&request.kontakt);
|
|
||||||
let telefon = sanitize_input(&request.telefon);
|
|
||||||
let skladu = sanitize_input(&request.skladu);
|
|
||||||
let fax = sanitize_input(&request.fax);
|
|
||||||
|
|
||||||
let adresar = sqlx::query_as!(
|
|
||||||
Adresar,
|
|
||||||
r#"
|
|
||||||
UPDATE adresar
|
|
||||||
SET
|
|
||||||
firma = $2,
|
|
||||||
kz = $3,
|
|
||||||
drc = $4,
|
|
||||||
ulica = $5,
|
|
||||||
psc = $6,
|
|
||||||
mesto = $7,
|
|
||||||
stat = $8,
|
|
||||||
banka = $9,
|
|
||||||
ucet = $10,
|
|
||||||
skladm = $11,
|
|
||||||
ico = $12,
|
|
||||||
kontakt = $13,
|
|
||||||
telefon = $14,
|
|
||||||
skladu = $15,
|
|
||||||
fax = $16
|
|
||||||
WHERE id = $1 AND deleted = FALSE
|
|
||||||
RETURNING
|
|
||||||
id,
|
|
||||||
deleted,
|
|
||||||
firma,
|
|
||||||
kz,
|
|
||||||
drc,
|
|
||||||
ulica,
|
|
||||||
psc,
|
|
||||||
mesto,
|
|
||||||
stat,
|
|
||||||
banka,
|
|
||||||
ucet,
|
|
||||||
skladm,
|
|
||||||
ico,
|
|
||||||
kontakt,
|
|
||||||
telefon,
|
|
||||||
skladu,
|
|
||||||
fax
|
|
||||||
"#,
|
|
||||||
request.id,
|
|
||||||
request.firma,
|
|
||||||
kz,
|
|
||||||
drc,
|
|
||||||
ulica,
|
|
||||||
psc,
|
|
||||||
mesto,
|
|
||||||
stat,
|
|
||||||
banka,
|
|
||||||
ucet,
|
|
||||||
skladm,
|
|
||||||
ico,
|
|
||||||
kontakt,
|
|
||||||
telefon,
|
|
||||||
skladu,
|
|
||||||
fax
|
|
||||||
)
|
|
||||||
.fetch_one(db_pool)
|
|
||||||
.await
|
|
||||||
.map_err(|e| Status::internal(e.to_string()))?;
|
|
||||||
|
|
||||||
Ok(AdresarResponse {
|
|
||||||
id: adresar.id,
|
|
||||||
firma: adresar.firma,
|
|
||||||
kz: adresar.kz.unwrap_or_default(),
|
|
||||||
drc: adresar.drc.unwrap_or_default(),
|
|
||||||
ulica: adresar.ulica.unwrap_or_default(),
|
|
||||||
psc: adresar.psc.unwrap_or_default(),
|
|
||||||
mesto: adresar.mesto.unwrap_or_default(),
|
|
||||||
stat: adresar.stat.unwrap_or_default(),
|
|
||||||
banka: adresar.banka.unwrap_or_default(),
|
|
||||||
ucet: adresar.ucet.unwrap_or_default(),
|
|
||||||
skladm: adresar.skladm.unwrap_or_default(),
|
|
||||||
ico: adresar.ico.unwrap_or_default(),
|
|
||||||
kontakt: adresar.kontakt.unwrap_or_default(),
|
|
||||||
telefon: adresar.telefon.unwrap_or_default(),
|
|
||||||
skladu: adresar.skladu.unwrap_or_default(),
|
|
||||||
fax: adresar.fax.unwrap_or_default(),
|
|
||||||
})
|
|
||||||
}
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
// src/adresar/mod.rs
|
|
||||||
|
|
||||||
pub mod models;
|
|
||||||
pub mod handlers;
|
|
||||||
|
|
||||||
// #[cfg(test)]
|
|
||||||
// pub mod tests;
|
|
||||||
@@ -1,23 +0,0 @@
|
|||||||
// src/adresar/models.rs
|
|
||||||
use serde::{Deserialize, Serialize};
|
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize)]
|
|
||||||
pub struct Adresar {
|
|
||||||
pub id: i64,
|
|
||||||
pub deleted: bool,
|
|
||||||
pub firma: String,
|
|
||||||
pub kz: Option<String>,
|
|
||||||
pub drc: Option<String>,
|
|
||||||
pub ulica: Option<String>,
|
|
||||||
pub psc: Option<String>,
|
|
||||||
pub mesto: Option<String>,
|
|
||||||
pub stat: Option<String>,
|
|
||||||
pub banka: Option<String>,
|
|
||||||
pub ucet: Option<String>,
|
|
||||||
pub skladm: Option<String>,
|
|
||||||
pub ico: Option<String>,
|
|
||||||
pub kontakt: Option<String>,
|
|
||||||
pub telefon: Option<String>,
|
|
||||||
pub skladu: Option<String>,
|
|
||||||
pub fax: Option<String>,
|
|
||||||
}
|
|
||||||
@@ -4,8 +4,6 @@ pub mod auth;
|
|||||||
pub mod indexer;
|
pub mod indexer;
|
||||||
pub mod search_schema;
|
pub mod search_schema;
|
||||||
pub mod server;
|
pub mod server;
|
||||||
pub mod adresar;
|
|
||||||
pub mod uctovnictvo;
|
|
||||||
pub mod shared;
|
pub mod shared;
|
||||||
pub mod table_structure;
|
pub mod table_structure;
|
||||||
pub mod table_definition;
|
pub mod table_definition;
|
||||||
|
|||||||
@@ -1,69 +0,0 @@
|
|||||||
// src/server/services/adresar_service.rs
|
|
||||||
use tonic::{Request, Response, Status};
|
|
||||||
use common::proto::multieko2::adresar::{
|
|
||||||
adresar_server::Adresar,
|
|
||||||
PostAdresarRequest, AdresarResponse, GetAdresarRequest, PutAdresarRequest,
|
|
||||||
DeleteAdresarRequest, DeleteAdresarResponse,
|
|
||||||
};
|
|
||||||
use common::proto::multieko2::common::{Empty, CountResponse, PositionRequest};
|
|
||||||
use crate::adresar::handlers::{
|
|
||||||
post_adresar, get_adresar, put_adresar, delete_adresar,
|
|
||||||
get_adresar_count, get_adresar_by_position,
|
|
||||||
};
|
|
||||||
use sqlx::PgPool;
|
|
||||||
|
|
||||||
#[derive(Debug)]
|
|
||||||
pub struct AdresarService {
|
|
||||||
pub db_pool: PgPool,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[tonic::async_trait]
|
|
||||||
impl Adresar for AdresarService {
|
|
||||||
async fn post_adresar(
|
|
||||||
&self,
|
|
||||||
request: Request<PostAdresarRequest>,
|
|
||||||
) -> Result<Response<AdresarResponse>, Status> {
|
|
||||||
let response = post_adresar(&self.db_pool, request.into_inner()).await?;
|
|
||||||
Ok(Response::new(response))
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn get_adresar(
|
|
||||||
&self,
|
|
||||||
request: Request<GetAdresarRequest>,
|
|
||||||
) -> Result<Response<AdresarResponse>, Status> {
|
|
||||||
let response = get_adresar(&self.db_pool, request.into_inner()).await?;
|
|
||||||
Ok(Response::new(response))
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn put_adresar(
|
|
||||||
&self,
|
|
||||||
request: Request<PutAdresarRequest>,
|
|
||||||
) -> Result<Response<AdresarResponse>, Status> {
|
|
||||||
let response = put_adresar(&self.db_pool, request.into_inner()).await?;
|
|
||||||
Ok(Response::new(response))
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn delete_adresar(
|
|
||||||
&self,
|
|
||||||
request: Request<DeleteAdresarRequest>,
|
|
||||||
) -> Result<Response<DeleteAdresarResponse>, Status> {
|
|
||||||
let response = delete_adresar(&self.db_pool, request.into_inner()).await?;
|
|
||||||
Ok(Response::new(response))
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn get_adresar_count(
|
|
||||||
&self,
|
|
||||||
request: Request<Empty>,
|
|
||||||
) -> Result<Response<CountResponse>, Status> {
|
|
||||||
let response = get_adresar_count(&self.db_pool, request.into_inner()).await?;
|
|
||||||
Ok(Response::new(response))
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn get_adresar_by_position(
|
|
||||||
&self,
|
|
||||||
request: Request<PositionRequest>,
|
|
||||||
) -> Result<Response<AdresarResponse>, Status> {
|
|
||||||
let response = get_adresar_by_position(&self.db_pool, request.into_inner()).await?;
|
|
||||||
Ok(Response::new(response))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,60 +0,0 @@
|
|||||||
// src/server/services/uctovnictvo_service.rs
|
|
||||||
use tonic::{Request, Response, Status};
|
|
||||||
use common::proto::multieko2::uctovnictvo::{
|
|
||||||
uctovnictvo_server::Uctovnictvo,
|
|
||||||
PostUctovnictvoRequest, UctovnictvoResponse, GetUctovnictvoRequest, PutUctovnictvoRequest,
|
|
||||||
};
|
|
||||||
use crate::uctovnictvo::handlers::{
|
|
||||||
post_uctovnictvo, get_uctovnictvo, get_uctovnictvo_count,
|
|
||||||
get_uctovnictvo_by_position, put_uctovnictvo,
|
|
||||||
};
|
|
||||||
use common::proto::multieko2::common::{Empty, CountResponse, PositionRequest};
|
|
||||||
use sqlx::PgPool;
|
|
||||||
|
|
||||||
#[derive(Debug)]
|
|
||||||
pub struct UctovnictvoService {
|
|
||||||
pub db_pool: PgPool,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[tonic::async_trait]
|
|
||||||
impl Uctovnictvo for UctovnictvoService {
|
|
||||||
async fn post_uctovnictvo(
|
|
||||||
&self,
|
|
||||||
request: Request<PostUctovnictvoRequest>,
|
|
||||||
) -> Result<Response<UctovnictvoResponse>, Status> {
|
|
||||||
let response = post_uctovnictvo(&self.db_pool, request.into_inner()).await?;
|
|
||||||
Ok(Response::new(response))
|
|
||||||
}
|
|
||||||
|
|
||||||
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))
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn get_uctovnictvo_count(
|
|
||||||
&self,
|
|
||||||
request: Request<Empty>,
|
|
||||||
) -> Result<Response<CountResponse>, Status> {
|
|
||||||
let response = get_uctovnictvo_count(&self.db_pool, request.into_inner()).await?;
|
|
||||||
Ok(Response::new(response))
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn get_uctovnictvo_by_position(
|
|
||||||
&self,
|
|
||||||
request: Request<PositionRequest>,
|
|
||||||
) -> Result<Response<UctovnictvoResponse>, Status> {
|
|
||||||
let response = get_uctovnictvo_by_position(&self.db_pool, request.into_inner()).await?;
|
|
||||||
Ok(Response::new(response))
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn put_uctovnictvo(
|
|
||||||
&self,
|
|
||||||
request: Request<PutUctovnictvoRequest>,
|
|
||||||
) -> Result<Response<UctovnictvoResponse>, Status> {
|
|
||||||
let response = put_uctovnictvo(&self.db_pool, request.into_inner()).await?;
|
|
||||||
Ok(Response::new(response))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,58 +0,0 @@
|
|||||||
POST
|
|
||||||
❯ grpcurl -plaintext -d '{
|
|
||||||
"adresar_id": 1,
|
|
||||||
"c_dokladu": "DOC123",
|
|
||||||
"datum": "01:10:2023",
|
|
||||||
"c_faktury": "INV123",
|
|
||||||
"obsah": "Sample content",
|
|
||||||
"stredisko": "Center A",
|
|
||||||
"c_uctu": "ACC123",
|
|
||||||
"md": "MD123",
|
|
||||||
"identif": "ID123",
|
|
||||||
"poznanka": "Sample note",
|
|
||||||
"firma": "AAA"
|
|
||||||
}' localhost:50051 multieko2.uctovnictvo.Uctovnictvo/PostUctovnictvo
|
|
||||||
{
|
|
||||||
"id": "3",
|
|
||||||
"adresarId": "1",
|
|
||||||
"cDokladu": "DOC123",
|
|
||||||
"datum": "2023-10-01",
|
|
||||||
"cFaktury": "INV123",
|
|
||||||
"obsah": "Sample content",
|
|
||||||
"stredisko": "Center A",
|
|
||||||
"cUctu": "ACC123",
|
|
||||||
"md": "MD123",
|
|
||||||
"identif": "ID123",
|
|
||||||
"poznanka": "Sample note",
|
|
||||||
"firma": "AAA"
|
|
||||||
}
|
|
||||||
|
|
||||||
PUT
|
|
||||||
❯ grpcurl -plaintext -d '{
|
|
||||||
"id": '1',
|
|
||||||
"adresar_id": 1,
|
|
||||||
"c_dokladu": "UPDATED-DOC",
|
|
||||||
"datum": "15.11.2023",
|
|
||||||
"c_faktury": "UPDATED-INV",
|
|
||||||
"obsah": "Updated content",
|
|
||||||
"stredisko": "Updated Center",
|
|
||||||
"c_uctu": "UPD-ACC",
|
|
||||||
"md": "UPD-MD",
|
|
||||||
"identif": "UPD-ID",
|
|
||||||
"poznanka": "Updated note",
|
|
||||||
"firma": "UPD"
|
|
||||||
}' localhost:50051 multieko2.uctovnictvo.Uctovnictvo/PutUctovnictvo
|
|
||||||
{
|
|
||||||
"id": "1",
|
|
||||||
"adresarId": "1",
|
|
||||||
"cDokladu": "UPDATED-DOC",
|
|
||||||
"datum": "15.11.2023",
|
|
||||||
"cFaktury": "UPDATED-INV",
|
|
||||||
"obsah": "Updated content",
|
|
||||||
"stredisko": "Updated Center",
|
|
||||||
"cUctu": "UPD-ACC",
|
|
||||||
"md": "UPD-MD",
|
|
||||||
"identif": "UPD-ID",
|
|
||||||
"poznanka": "Updated note",
|
|
||||||
"firma": "UPD"
|
|
||||||
}
|
|
||||||
@@ -1,41 +0,0 @@
|
|||||||
❯ grpcurl -plaintext -d '{}' localhost:50051 multieko2.uctovnictvo.Uctovnictvo/GetUctovnictvoCount
|
|
||||||
|
|
||||||
{
|
|
||||||
"count": "4"
|
|
||||||
}
|
|
||||||
❯ grpcurl -plaintext -d '{
|
|
||||||
"position": 2
|
|
||||||
}' localhost:50051 multieko2.uctovnictvo.Uctovnictvo/GetUctovnictvoByPosition
|
|
||||||
|
|
||||||
{
|
|
||||||
"id": "2",
|
|
||||||
"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"
|
|
||||||
}
|
|
||||||
❯ 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,12 +0,0 @@
|
|||||||
// src/uctovnictvo/handlers.rs
|
|
||||||
pub mod post_uctovnictvo;
|
|
||||||
pub mod get_uctovnictvo;
|
|
||||||
pub mod get_uctovnictvo_count;
|
|
||||||
pub mod get_uctovnictvo_by_position;
|
|
||||||
pub mod put_uctovnictvo;
|
|
||||||
|
|
||||||
pub use post_uctovnictvo::post_uctovnictvo;
|
|
||||||
pub use get_uctovnictvo::get_uctovnictvo;
|
|
||||||
pub use get_uctovnictvo_count::get_uctovnictvo_count;
|
|
||||||
pub use get_uctovnictvo_by_position::get_uctovnictvo_by_position;
|
|
||||||
pub use put_uctovnictvo::put_uctovnictvo;
|
|
||||||
@@ -1,51 +0,0 @@
|
|||||||
// src/uctovnictvo/handlers/get_uctovnictvo.rs
|
|
||||||
use tonic::Status;
|
|
||||||
use sqlx::PgPool;
|
|
||||||
use crate::uctovnictvo::models::Uctovnictvo;
|
|
||||||
use common::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,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
@@ -1,34 +0,0 @@
|
|||||||
// src/uctovnictvo/handlers/get_uctovnictvo_by_position.rs
|
|
||||||
use tonic::Status;
|
|
||||||
use sqlx::PgPool;
|
|
||||||
use common::proto::multieko2::common::PositionRequest;
|
|
||||||
use super::get_uctovnictvo;
|
|
||||||
|
|
||||||
pub async fn get_uctovnictvo_by_position(
|
|
||||||
db_pool: &PgPool,
|
|
||||||
request: PositionRequest,
|
|
||||||
) -> Result<common::proto::multieko2::uctovnictvo::UctovnictvoResponse, Status> {
|
|
||||||
if request.position < 1 {
|
|
||||||
return Err(Status::invalid_argument("Position must be at least 1"));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Find the ID of the Nth non-deleted record
|
|
||||||
let id: i64 = sqlx::query_scalar!(
|
|
||||||
r#"
|
|
||||||
SELECT id
|
|
||||||
FROM uctovnictvo
|
|
||||||
WHERE deleted = FALSE
|
|
||||||
ORDER BY id ASC
|
|
||||||
OFFSET $1
|
|
||||||
LIMIT 1
|
|
||||||
"#,
|
|
||||||
request.position - 1
|
|
||||||
)
|
|
||||||
.fetch_optional(db_pool)
|
|
||||||
.await
|
|
||||||
.map_err(|e| Status::internal(e.to_string()))?
|
|
||||||
.ok_or_else(|| Status::not_found("Position out of bounds"))?;
|
|
||||||
|
|
||||||
// Now fetch the complete record using the existing get_uctovnictvo function
|
|
||||||
get_uctovnictvo(db_pool, common::proto::multieko2::uctovnictvo::GetUctovnictvoRequest { id }).await
|
|
||||||
}
|
|
||||||
@@ -1,23 +0,0 @@
|
|||||||
// src/uctovnictvo/handlers/get_uctovnictvo_count.rs
|
|
||||||
use tonic::Status;
|
|
||||||
use sqlx::PgPool;
|
|
||||||
use common::proto::multieko2::common::{CountResponse, Empty};
|
|
||||||
|
|
||||||
pub async fn get_uctovnictvo_count(
|
|
||||||
db_pool: &PgPool,
|
|
||||||
_request: Empty,
|
|
||||||
) -> Result<CountResponse, Status> {
|
|
||||||
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 })
|
|
||||||
}
|
|
||||||
@@ -1,73 +0,0 @@
|
|||||||
// src/uctovnictvo/handlers/post_uctovnictvo.rs
|
|
||||||
use tonic::Status;
|
|
||||||
use sqlx::PgPool;
|
|
||||||
use crate::uctovnictvo::models::Uctovnictvo;
|
|
||||||
use common::proto::multieko2::uctovnictvo::{PostUctovnictvoRequest, UctovnictvoResponse};
|
|
||||||
use crate::shared::date_utils::parse_date_with_multiple_formats; // Import from shared module
|
|
||||||
|
|
||||||
pub async fn post_uctovnictvo(
|
|
||||||
db_pool: &PgPool,
|
|
||||||
request: PostUctovnictvoRequest,
|
|
||||||
) -> Result<UctovnictvoResponse, Status> {
|
|
||||||
let datum = parse_date_with_multiple_formats(&request.datum)
|
|
||||||
.ok_or_else(|| Status::invalid_argument(format!("Invalid date format: {}", request.datum)))?;
|
|
||||||
|
|
||||||
// Pass the NaiveDate value directly.
|
|
||||||
let uctovnictvo = sqlx::query_as!(
|
|
||||||
Uctovnictvo,
|
|
||||||
r#"
|
|
||||||
INSERT INTO uctovnictvo (
|
|
||||||
adresar_id, c_dokladu, datum, c_faktury, obsah, stredisko,
|
|
||||||
c_uctu, md, identif, poznanka, firma, deleted
|
|
||||||
)
|
|
||||||
VALUES (
|
|
||||||
$1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12
|
|
||||||
)
|
|
||||||
RETURNING
|
|
||||||
id,
|
|
||||||
deleted,
|
|
||||||
adresar_id,
|
|
||||||
c_dokladu,
|
|
||||||
datum as "datum: chrono::NaiveDate",
|
|
||||||
c_faktury,
|
|
||||||
obsah,
|
|
||||||
stredisko,
|
|
||||||
c_uctu,
|
|
||||||
md,
|
|
||||||
identif,
|
|
||||||
poznanka,
|
|
||||||
firma
|
|
||||||
"#,
|
|
||||||
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,
|
|
||||||
false
|
|
||||||
)
|
|
||||||
.fetch_one(db_pool)
|
|
||||||
.await
|
|
||||||
.map_err(|e| Status::internal(e.to_string()))?;
|
|
||||||
|
|
||||||
// Return the response with formatted date
|
|
||||||
Ok(UctovnictvoResponse {
|
|
||||||
id: uctovnictvo.id,
|
|
||||||
adresar_id: uctovnictvo.adresar_id,
|
|
||||||
c_dokladu: uctovnictvo.c_dokladu,
|
|
||||||
datum: uctovnictvo.datum.format("%d.%m.%Y").to_string(), // Standard Slovak format
|
|
||||||
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,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
@@ -1,78 +0,0 @@
|
|||||||
// 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,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
@@ -1,4 +0,0 @@
|
|||||||
// src/uctovnictvo/mod.rs
|
|
||||||
|
|
||||||
pub mod models;
|
|
||||||
pub mod handlers;
|
|
||||||
@@ -1,21 +0,0 @@
|
|||||||
// src/uctovnictvo/models.rs
|
|
||||||
use chrono::NaiveDate;
|
|
||||||
use serde::{Deserialize, Serialize};
|
|
||||||
|
|
||||||
#[derive(Debug, sqlx::FromRow, Serialize, Deserialize)]
|
|
||||||
pub struct Uctovnictvo {
|
|
||||||
pub id: i64,
|
|
||||||
pub deleted: bool,
|
|
||||||
pub adresar_id: i64,
|
|
||||||
pub c_dokladu: String,
|
|
||||||
pub datum: NaiveDate,
|
|
||||||
pub c_faktury: String,
|
|
||||||
pub obsah: Option<String>,
|
|
||||||
pub stredisko: Option<String>,
|
|
||||||
pub c_uctu: Option<String>,
|
|
||||||
pub md: Option<String>,
|
|
||||||
pub identif: Option<String>,
|
|
||||||
pub poznanka: Option<String>,
|
|
||||||
pub firma: String,
|
|
||||||
}
|
|
||||||
|
|
||||||
Reference in New Issue
Block a user