Added customers overview, booking detail dialog and about dialog.
This commit is contained in:
+20
-1
@@ -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))
|
||||
}
|
||||
Reference in New Issue
Block a user