Added customers overview, booking detail dialog and about dialog.

This commit is contained in:
2024-02-15 16:46:57 +01:00
parent 952f8fbe94
commit 549ec86684
11 changed files with 186 additions and 4041 deletions
+20 -1
View File
@@ -1,11 +1,14 @@
use cfg_if::cfg_if;
use leptos::{server, ServerFnError};
use crate::backend::data::ApiResponse;
use crate::backend::data::Customer;
cfg_if! { if #[cfg(feature = "ssr")] {
use sqlx::{Postgres, Transaction};
use sqlx::{query_as, query};
use sqlx::Error;
use crate::backend::data::Customer;
use std::ops::DerefMut;
use leptos::expect_context;
pub async fn find_customer_by_email(email: &str, tx: &mut Transaction<'_, Postgres>) -> Option<Customer> {
let customer = query_as::<_, Customer>("SELECT * FROM customer WHERE email = $1")
@@ -48,3 +51,19 @@ cfg_if! { if #[cfg(feature = "ssr")] {
Ok(find_customer_by_email(email, tx).await.ok_or(Error::RowNotFound)?)
}
}}
#[server]
pub async fn get_customers() -> Result<ApiResponse<Vec<Customer>>, ServerFnError> {
use crate::backend::get_pool;
use crate::perm_check;
perm_check!(is_logged_in);
let pool = get_pool().await?;
let customers = query_as::<_, Customer>("SELECT * FROM customer")
.fetch_all(&pool)
.await?;
Ok(ApiResponse::Data(customers))
}