pub const WORKSPACE_MANIFEST: &str = "Cargo.toml";
pub const CONTEXTS_DIR: &str = "contextos";
pub const NUCLEO_DIR: &str = "nucleo";
pub const NUCLEO_SRC: &str = "nucleo/src";
pub const MIGRATIONS_DIR: &str = "migraciones";
pub const MIGRADOR_DIR: &str = "migrador";
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Layer {
Domain,
Application,
Infrastructure,
Rest,
}
impl Layer {
pub const ALL: [Layer; 4] = [
Layer::Domain,
Layer::Application,
Layer::Infrastructure,
Layer::Rest,
];
pub fn dir(self) -> &'static str {
match self {
Layer::Domain => "dominio",
Layer::Application => "aplicacion",
Layer::Infrastructure => "infraestructura",
Layer::Rest => "rest",
}
}
pub fn prefix(self) -> &'static str {
match self {
Layer::Domain => "dominio",
Layer::Application => "aplicacion",
Layer::Infrastructure => "infra",
Layer::Rest => "rest",
}
}
}
pub fn context_dir(c: &str) -> String {
format!("{CONTEXTS_DIR}/{c}")
}
pub fn crate_name(c: &str, layer: Layer) -> String {
format!("{}_{c}", layer.prefix())
}
pub fn crate_dir(c: &str, layer: Layer) -> String {
format!("{CONTEXTS_DIR}/{c}/{}", layer.dir())
}
pub fn crate_manifest(c: &str, layer: Layer) -> String {
format!("{}/Cargo.toml", crate_dir(c, layer))
}
pub fn crate_lib(c: &str, layer: Layer) -> String {
format!("{}/src/lib.rs", crate_dir(c, layer))
}
pub fn crate_file(c: &str, layer: Layer, module: &str) -> String {
format!("{}/src/{module}.rs", crate_dir(c, layer))
}
pub fn domain_file(c: &str, module: &str) -> String {
crate_file(c, Layer::Domain, module)
}
pub fn use_case(c: &str, uc: &str) -> String {
crate_file(c, Layer::Application, uc)
}
pub fn mother(c: &str) -> String {
format!("{}/src/pruebas/madres.rs", crate_dir(c, Layer::Domain))
}
pub fn infra_file(c: &str, module: &str) -> String {
crate_file(c, Layer::Infrastructure, module)
}
pub fn rest_file(c: &str, module: &str) -> String {
crate_file(c, Layer::Rest, module)
}
pub const MAIL_CONTEXT: &str = "correo";
pub fn mail_port(name: &str) -> String {
crate_file(MAIL_CONTEXT, Layer::Domain, name)
}
pub fn mail_adapter(name: &str) -> String {
crate_file(MAIL_CONTEXT, Layer::Infrastructure, name)
}
pub fn mail_templates_dir(name: &str) -> String {
format!(
"{}/plantillas/{name}",
crate_dir(MAIL_CONTEXT, Layer::Infrastructure)
)
}
pub const USER_CONTEXT: &str = "usuario";
pub const KEYCLOAK_REALM: &str = "keycloak/realm.json";
pub const CABLEADO_MANIFEST: &str = "presentacion/cableado/Cargo.toml";
pub const CABLEADO_LIB: &str = "presentacion/cableado/src/lib.rs";
pub const API_MANIFEST: &str = "presentacion/api/Cargo.toml";
pub const BOOTSTRAP_RS: &str = "presentacion/api/src/generado/bootstrap.rs";
pub const WORKER_DIR: &str = "presentacion/worker";
pub const WORKER_MANIFEST: &str = "presentacion/worker/Cargo.toml";
pub const WORKER_SRC: &str = "presentacion/worker/src";
pub const WORKER_GENERATED_DIR: &str = "presentacion/worker/src/generado";
pub const REGISTRY_RS: &str = "presentacion/worker/src/generado/registro.rs";
pub const CONSUMERS_RS: &str = "presentacion/worker/src/consumidores.rs";
pub fn consumer(name: &str) -> String {
format!("{WORKER_SRC}/consumidores/{name}.rs")
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn should_name_each_crate_after_its_layer_and_context() {
let names: Vec<String> = Layer::ALL
.iter()
.map(|l| crate_name("order_item", *l))
.collect();
assert_eq!(
names,
[
"dominio_order_item",
"aplicacion_order_item",
"infra_order_item",
"rest_order_item"
]
);
assert_eq!(
crate_dir("order_item", Layer::Infrastructure),
"contextos/order_item/infraestructura"
);
}
}