diff --git a/backend/Cargo.lock b/backend/Cargo.lock index 9d6c881..7090c17 100644 --- a/backend/Cargo.lock +++ b/backend/Cargo.lock @@ -20,6 +20,12 @@ dependencies = [ "libc", ] +[[package]] +name = "arrayvec" +version = "0.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8da52d66c7071e2e3fa2a1e5c6d088fec47b593032b254f5e980de8ea54454d6" + [[package]] name = "async-trait" version = "0.1.58" @@ -96,8 +102,10 @@ dependencies = [ "chrono", "dotenvy", "hyper", + "iban_validate", "once_cell", "openssl", + "regex", "reqwest", "serde", "serde_json", @@ -459,6 +467,16 @@ dependencies = [ "cxx-build", ] +[[package]] +name = "iban_validate" +version = "4.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cc1d358f7ae89819e8656f1b495c9d760a9ca315998b12d589dc516c9f81ed08" +dependencies = [ + "arrayvec", + "serde", +] + [[package]] name = "idna" version = "0.2.3" @@ -873,9 +891,9 @@ dependencies = [ [[package]] name = "regex" -version = "1.7.0" +version = "1.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e076559ef8e241f2ae3479e36f97bd5741c0330689e217ad51ce2c76808b868a" +checksum = "48aaa5748ba571fb95cd2c85c09f629215d3a6ece942baa100950af03a34f733" dependencies = [ "aho-corasick", "memchr", diff --git a/backend/Cargo.toml b/backend/Cargo.toml index a453bb1..bc93948 100644 --- a/backend/Cargo.toml +++ b/backend/Cargo.toml @@ -10,8 +10,10 @@ axum = { version = "0.6.0", features = ["multipart"] } chrono = { version = "0.4.23", features = ["serde"] } dotenvy = "0.15.6" hyper = { version = "0.14.23", features = ["full"] } +iban_validate = { version = "4.0.1", features = ["serde"] } once_cell = "1.17.0" openssl = { version = "0.10.45", features = ["vendored"] } +regex = "1.7.1" reqwest = { version = "0.11.13", features = ["json"] } serde = { version = "1.0.147", features = ["derive"] } serde_json = "1.0.91" diff --git a/backend/src/main.rs b/backend/src/main.rs index c757e92..a7089be 100644 --- a/backend/src/main.rs +++ b/backend/src/main.rs @@ -10,7 +10,8 @@ use axum::{ use chrono::NaiveDate; use dotenvy::dotenv; use hyper::StatusCode; -use serde::Deserialize; +use iban::Iban; +use serde::{Deserialize, Serialize}; use std::net::SocketAddr; use tower_http::{limit::RequestBodyLimitLayer, trace::TraceLayer}; use tracing_subscriber::{ @@ -57,7 +58,18 @@ async fn main() { .unwrap(); } -#[derive(Deserialize, Validate, Debug)] +#[derive(Debug, Validate, Deserialize, Serialize)] +#[serde(rename_all = "camelCase")] +struct RequestInvoiceRow { + #[validate(range(min = 1))] + quantity: i32, + #[validate(range(min = 0))] + unit_price: f64, + #[validate(length(min = 1, max = 300))] + description: String, +} + +#[derive(Debug, Validate, Deserialize)] #[serde(rename_all = "camelCase")] struct RequestBody { #[validate(length(min = 1, max = 300))] @@ -66,7 +78,24 @@ struct RequestBody { last_name: String, #[validate(length(min = 1, max = 300))] street_address: String, + #[validate(length(min = 1, max = 10))] + zip: String, + #[validate(length(min = 1, max = 300))] + city: String, + #[validate(length(min = 1, max = 40))] + phone_number: String, + #[validate(length(min = 1, max = 600))] + email: String, + bank_account_number: Iban, invoice_date: NaiveDate, + #[validate(length(min = 1, max = 300))] + topic: String, + #[validate(length(min = 1, max = 5000))] + description: String, + #[validate(length(min = 1, max = 1000))] + other: String, + #[validate(length(min = 1))] + invoice_rows: Vec, } async fn handler(multipart: Multipart) -> Result { diff --git a/backend/src/procountor.rs b/backend/src/procountor.rs index 5bee9eb..b2b049a 100644 --- a/backend/src/procountor.rs +++ b/backend/src/procountor.rs @@ -282,7 +282,7 @@ struct InvoiceRow { product: String, quantity: i32, unit: ProductUnit, - unit_price: f32, + unit_price: f64, discount_percent: i32, vat_percent: i32, vat_status: i32,