tenis booking site done by claude

This commit is contained in:
Priec
2026-05-16 00:02:39 +02:00
parent 8b7f883f14
commit 7d05209d48
40 changed files with 1180 additions and 632 deletions

View File

@@ -0,0 +1,55 @@
//! Seeds the single hardcoded admin user (and a default court) on boot.
//!
//! Credentials are read from the environment (`.env`):
//! `ADMIN_EMAIL`, `ADMIN_PASSWORD`, `ADMIN_NAME`.
use async_trait::async_trait;
use loco_rs::prelude::*;
use crate::models::_entities::courts;
use crate::models::users::{self, RegisterParams};
pub struct AdminSeeder;
#[async_trait]
impl Initializer for AdminSeeder {
fn name(&self) -> String {
"admin-seeder".to_string()
}
async fn before_run(&self, ctx: &AppContext) -> Result<()> {
let email = std::env::var("ADMIN_EMAIL").unwrap_or_default();
let password = std::env::var("ADMIN_PASSWORD").unwrap_or_default();
let name = std::env::var("ADMIN_NAME").unwrap_or_else(|_| "Admin".to_string());
if email.is_empty() || password.is_empty() {
tracing::warn!("ADMIN_EMAIL / ADMIN_PASSWORD not set in .env — admin not seeded");
} else if users::Model::find_by_email(&ctx.db, &email).await.is_err() {
users::Model::create_with_password(
&ctx.db,
&RegisterParams {
email: email.clone(),
password,
name,
},
)
.await?;
tracing::info!(admin = %email, "admin user seeded");
}
// The calendar is per-court, so make sure at least one court exists.
if courts::Entity::find().one(&ctx.db).await?.is_none() {
courts::ActiveModel {
name: Set(Some("Court 1".to_string())),
surface: Set(Some("Clay".to_string())),
indoor: Set(Some(false)),
..Default::default()
}
.insert(&ctx.db)
.await?;
tracing::info!("default court seeded");
}
Ok(())
}
}

View File

@@ -1 +1,2 @@
pub mod admin_seeder;
pub mod view_engine;

View File

@@ -24,7 +24,7 @@ impl Initializer for ViewEngineInitializer {
async fn after_routes(&self, router: AxumRouter, _ctx: &AppContext) -> Result<AxumRouter> {
let tera_engine = if std::path::Path::new(I18N_DIR).exists() {
let arc = std::sync::Arc::new(
ArcLoader::builder(&I18N_DIR, unic_langid::langid!("en-US"))
ArcLoader::builder(&I18N_DIR, unic_langid::langid!("en"))
.shared_resources(Some(&[I18N_SHARED.into()]))
.customize(|bundle| bundle.set_use_isolating(false))
.build()