Skip to content
This repository has been archived by the owner on Jan 26, 2024. It is now read-only.

Backend API #4

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 20 additions & 2 deletions backend/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions backend/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
33 changes: 31 additions & 2 deletions backend/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand Down Expand Up @@ -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))]
Expand All @@ -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<RequestInvoiceRow>,
}

async fn handler(multipart: Multipart) -> Result<String, (StatusCode, String)> {
Expand Down
2 changes: 1 addition & 1 deletion backend/src/procountor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down