refactor: DDD/CQRS architecture, unified crate layout
- crates: common→application, api→presentation, infrastructure/*→adapters/* - new crates: api-types, infra-wiring - domain: errors/, models/, value_objects/, ports/, services/ - application: CQRS use cases (songs/, tabs/) w/ commands, queries, deps - unified DomainError replaces RepositoryError - workspace deps, unused dep cleanup - fix: parse plain-text chord lines (UG drops spans mid-song) - tests extracted to separate modules (tests/ dirs)
This commit is contained in:
6
crates/infra-wiring/Cargo.toml
Normal file
6
crates/infra-wiring/Cargo.toml
Normal file
@@ -0,0 +1,6 @@
|
||||
[package]
|
||||
name = "infra-wiring"
|
||||
version = "0.1.0"
|
||||
edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
54
crates/infra-wiring/src/config.rs
Normal file
54
crates/infra-wiring/src/config.rs
Normal file
@@ -0,0 +1,54 @@
|
||||
use std::env;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct AppConfig {
|
||||
pub database_url: String,
|
||||
pub host: String,
|
||||
pub port: u16,
|
||||
pub cors_origins: CorsOrigins,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum CorsOrigins {
|
||||
Any,
|
||||
List(Vec<String>),
|
||||
}
|
||||
|
||||
impl AppConfig {
|
||||
pub fn from_env() -> Self {
|
||||
let database_url =
|
||||
env::var("DATABASE_URL").unwrap_or_else(|_| "sqlite://./pocket-chords.db".into());
|
||||
|
||||
let host = env::var("HOST").unwrap_or_else(|_| "0.0.0.0".into());
|
||||
|
||||
let port = env::var("PORT")
|
||||
.ok()
|
||||
.and_then(|v| v.parse::<u16>().ok())
|
||||
.unwrap_or(8000);
|
||||
|
||||
let cors_origins = match env::var("CORS_ALLOWED_ORIGINS")
|
||||
.unwrap_or_else(|_| "*".into())
|
||||
.trim()
|
||||
.to_string()
|
||||
{
|
||||
s if s == "*" => CorsOrigins::Any,
|
||||
s => CorsOrigins::List(
|
||||
s.split(',')
|
||||
.map(|o| o.trim().to_string())
|
||||
.filter(|o| !o.is_empty())
|
||||
.collect(),
|
||||
),
|
||||
};
|
||||
|
||||
Self {
|
||||
database_url,
|
||||
host,
|
||||
port,
|
||||
cors_origins,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn bind_addr(&self) -> String {
|
||||
format!("{}:{}", self.host, self.port)
|
||||
}
|
||||
}
|
||||
3
crates/infra-wiring/src/lib.rs
Normal file
3
crates/infra-wiring/src/lib.rs
Normal file
@@ -0,0 +1,3 @@
|
||||
pub mod config;
|
||||
|
||||
pub use config::{AppConfig, CorsOrigins};
|
||||
Reference in New Issue
Block a user