You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
49 lines
1.2 KiB
Rust
49 lines
1.2 KiB
Rust
use crate::backend::data::Company;
|
|
use leptos::*;
|
|
|
|
#[server(GetCompany, "/api", "Url", "get_company")]
|
|
pub async fn get_company(cx: Scope) -> Result<Company, ServerFnError> {
|
|
use crate::backend::AppData;
|
|
use actix_web::web::Data;
|
|
use leptos_actix::extract;
|
|
|
|
let pool = extract(
|
|
cx,
|
|
|data: Data<AppData>| 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<AppData>| 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(())
|
|
}
|