diff --git a/Cargo.lock b/Cargo.lock
index 2ff8f3d..5ad4fc6 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -1504,6 +1504,12 @@ dependencies = [
"unicode-normalization",
]
+[[package]]
+name = "if_chain"
+version = "1.0.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "cb56e1aa765b4b4f3aadfab769793b7087bb03a4ea4920644a6d238e2df5b9ed"
+
[[package]]
name = "indexmap"
version = "1.9.3"
@@ -2503,6 +2509,7 @@ dependencies = [
"serde",
"sqlx",
"uuid",
+ "validator",
"wasm-bindgen",
"web-sys",
]
@@ -3558,6 +3565,48 @@ dependencies = [
"getrandom",
]
+[[package]]
+name = "validator"
+version = "0.16.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "b92f40481c04ff1f4f61f304d61793c7b56ff76ac1469f1beb199b1445b253bd"
+dependencies = [
+ "idna",
+ "lazy_static",
+ "regex",
+ "serde",
+ "serde_derive",
+ "serde_json",
+ "url",
+ "validator_derive",
+]
+
+[[package]]
+name = "validator_derive"
+version = "0.16.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "bc44ca3088bb3ba384d9aecf40c6a23a676ce23e09bdaca2073d99c207f864af"
+dependencies = [
+ "if_chain",
+ "lazy_static",
+ "proc-macro-error",
+ "proc-macro2",
+ "quote",
+ "regex",
+ "syn 1.0.109",
+ "validator_types",
+]
+
+[[package]]
+name = "validator_types"
+version = "0.16.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "111abfe30072511849c5910134e8baf8dc05de4c0e5903d681cbd5c9c4d611e3"
+dependencies = [
+ "proc-macro2",
+ "syn 1.0.109",
+]
+
[[package]]
name = "vcpkg"
version = "0.2.15"
diff --git a/Cargo.toml b/Cargo.toml
index 711ce2d..876a4cc 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -24,6 +24,7 @@ chrono = "0.4.26"
sqlx = { version = "0.7.1", optional = true, features = ["runtime-tokio-rustls", "postgres", "chrono", "rust_decimal"] }
rust_decimal = "1.31.0"
uuid = {version = "1.4.1", features = ["v4"]}
+validator = {version = "0.16.1", features = ["derive"]}
[features]
csr = ["leptos/csr", "leptos_meta/csr", "leptos_router/csr"]
diff --git a/src/app.rs b/src/app.rs
index 0d37386..fabe319 100644
--- a/src/app.rs
+++ b/src/app.rs
@@ -3,6 +3,7 @@ use leptos_meta::*;
use leptos_router::*;
use crate::locales::trl;
use crate::pages::home_page::HomePage;
+use crate::pages::settings::Settings;
#[component]
pub fn App(cx: Scope) -> impl IntoView {
@@ -98,21 +99,15 @@ pub fn App(cx: Scope) -> impl IntoView {
//
-
-
-
-
+
//
-
-
+
@@ -179,6 +174,7 @@ pub fn App(cx: Scope) -> impl IntoView {
}/>
+ }/>
diff --git a/src/backend/company.rs b/src/backend/company.rs
new file mode 100644
index 0000000..c76d4ee
--- /dev/null
+++ b/src/backend/company.rs
@@ -0,0 +1,48 @@
+use crate::backend::data::Company;
+use leptos::*;
+
+#[server(GetCompany, "/api", "Url", "get_company")]
+pub async fn get_company(cx: Scope) -> Result {
+ use crate::backend::AppData;
+ use actix_web::web::Data;
+ use leptos_actix::extract;
+
+ let pool = extract(
+ cx,
+ |data: Data| async move { data.db_pool().clone() },
+ )
+ .await?;
+
+ let cmp = sqlx::query_as::<_, Company>("SELECT * FROM company")
+ .fetch_one(&pool)
+ .await?;
+
+ Ok(cmp)
+}
+
+#[server(UpdateCompany, "/api", "Url", "update_company")]
+pub async fn update_company(cx: Scope, company: Company) -> Result<(), ServerFnError> {
+ use crate::backend::AppData;
+ use actix_web::web::Data;
+ use leptos_actix::extract;
+
+ let pool = extract(
+ cx,
+ |data: Data| async move { data.db_pool().clone() },
+ )
+ .await?;
+
+ sqlx::query(
+ "UPDATE company SET name = $1, street = $2, house_number = $3, zip_code = $4, city = $5 \
+ WHERE id = $6")
+ .bind(company.name.clone())
+ .bind(company.street.clone())
+ .bind(company.house_number.clone())
+ .bind(company.zip_code.clone())
+ .bind(company.city.clone())
+ .bind(company.id())
+ .execute(&pool)
+ .await?;
+
+ Ok(())
+}
diff --git a/src/backend/data.rs b/src/backend/data.rs
index c39a26d..beb19fa 100644
--- a/src/backend/data.rs
+++ b/src/backend/data.rs
@@ -1,14 +1,27 @@
use chrono::{NaiveDate, NaiveTime, Weekday};
use rust_decimal::Decimal;
+use serde::{Deserialize, Serialize};
use uuid::Uuid;
+use validator::Validate;
+#[derive(Clone, Serialize, Deserialize, Debug, PartialEq, Eq, Validate)]
+#[cfg_attr(feature = "ssr", derive(sqlx::FromRow))]
pub struct Company {
- id: u16,
- name: String,
- street: String,
- house_number: String,
- zip_code: String,
- city: String,
+ id: i32,
+ #[validate(length(min = 1,message = "Name cannot be empty"))]
+ pub name: String,
+ #[validate(length(min = 1,message = "Street cannot be empty"))]
+ pub street: String,
+ #[validate(length(min = 1,message = "House number cannot be empty"))]
+ pub house_number: String,
+ pub zip_code: String,
+ pub city: String,
+}
+
+impl Company {
+ pub fn id(&self) -> i32 {
+ self.id
+ }
}
pub struct User {
diff --git a/src/backend/mod.rs b/src/backend/mod.rs
index 07ff7c0..ea4d85e 100644
--- a/src/backend/mod.rs
+++ b/src/backend/mod.rs
@@ -1,6 +1,7 @@
use cfg_if::cfg_if;
pub mod data;
+pub mod company;
cfg_if!{
if #[cfg(feature = "ssr")] {
diff --git a/src/components/mod.rs b/src/components/mod.rs
index 1e2ebb4..8c68b2a 100644
--- a/src/components/mod.rs
+++ b/src/components/mod.rs
@@ -1,2 +1,4 @@
pub mod modal_box;
+pub mod server_err;
+pub mod validation_err;
diff --git a/src/components/modal_box.rs b/src/components/modal_box.rs
index bb23e3a..3a0cf37 100644
--- a/src/components/modal_box.rs
+++ b/src/components/modal_box.rs
@@ -75,3 +75,19 @@ pub fn ModalFooter(cx: Scope, children: Children) -> impl IntoView {
}
}
+
+#[component]
+pub fn DlgNotLoaded(cx: Scope, opener: DialogOpener, title: &'static str) -> impl IntoView {
+ view! {cx,
+
+
+ {trl(cx, "Entity not loaded")}
+
+
+
+
+
+ }
+}
diff --git a/src/components/server_err.rs b/src/components/server_err.rs
new file mode 100644
index 0000000..4740fe4
--- /dev/null
+++ b/src/components/server_err.rs
@@ -0,0 +1,27 @@
+use crate::components::modal_box::DialogOpener;
+use leptos::*;
+
+#[component]
+pub fn ServerErr(
+ cx: Scope,
+ result: RwSignal