Implemented public part and creating reservations.

This commit is contained in:
2024-02-01 09:18:00 +01:00
parent 0d4b4a0b3d
commit 6c7fd2e46f
16 changed files with 930 additions and 103 deletions
+34 -4
View File
@@ -1,14 +1,44 @@
use cfg_if::cfg_if;
use leptos::*;
use validator::Validate;
use crate::backend::data::{ApiResponse, ResProperty};
use crate::components::data_form::ForValidation;
#[server]
pub async fn get_properties() -> Result<ApiResponse<Vec<ResProperty>>, ServerFnError> {
cfg_if! { if #[cfg(feature = "ssr")] {
use crate::backend::get_pool;
let pool = get_pool().await?;
let props = sqlx::query_as::<_, ResProperty>("SELECT * FROM property").fetch_all(&pool).await?;
pub async fn get_props(filter: Option<String>) -> Result<Vec<ResProperty>, ServerFnError> {
let pool = get_pool().await?;
let props = if let Some(f) = filter {
sqlx::query_as::<_, ResProperty>(&format!("SELECT * FROM property WHERE {} ORDER BY id", f)).fetch_all(&pool).await?
} else {
sqlx::query_as::<_, ResProperty>("SELECT * FROM property ORDER BY id").fetch_all(&pool).await?
};
Ok(props)
}
pub async fn get_prop_by_id(id: i32) -> Result<ResProperty, ServerFnError> {
let pool = get_pool().await?;
let prop = sqlx::query_as::<_, ResProperty>("SELECT * FROM property WHERE id = $1")
.bind(id)
.fetch_one(&pool)
.await?;
Ok(prop)
}
}}
#[server]
pub async fn get_properties() -> Result<ApiResponse<Vec<ResProperty>>, ServerFnError> {
let props = get_props(None).await?;
Ok(ApiResponse::Data(props))
}
#[server]
pub async fn get_active_properties() -> Result<ApiResponse<Vec<ResProperty>>, ServerFnError> {
let props = get_props(Some("active = true".to_string())).await?;
Ok(ApiResponse::Data(props))
}