diff --git a/src/api/applications.rs b/src/api/applications.rs index 857aa15..23a1b6d 100644 --- a/src/api/applications.rs +++ b/src/api/applications.rs @@ -83,18 +83,35 @@ pub async fn get_ports_for_application( // ─── Mutations ──────────────────────────────────────────────────────────────── -/// Creates a new application and returns the created record. +/// Creates a new application, then associates the given port numbers. +/// +/// `ports` is a comma-separated list of port numbers (e.g. "80,443"). +/// An empty string means no ports are associated. #[server] -pub async fn create_application(name: String) -> Result { +pub async fn create_application(name: String, ports: String) -> Result { use sqlx::AnyPool; use crate::server::repository::applications as repo; let pool = use_context::() .ok_or_else(|| ServerFnError::new("Database pool not found in context"))?; - repo::create_application(&pool, &name) + let app = repo::create_application(&pool, &name) .await - .map_err(|e| ServerFnError::new(e.to_string())) + .map_err(|e| ServerFnError::new(e.to_string()))?; + + let port_numbers: Vec = ports + .split(',') + .filter_map(|s| s.trim().parse::().ok()) + .filter(|&p| p >= 1) + .collect(); + + for port_number in port_numbers { + repo::add_port_to_application(&pool, app.id, port_number) + .await + .map_err(|e| ServerFnError::new(e.to_string()))?; + } + + Ok(app) } /// Deletes an application and all its port associations. diff --git a/src/client/applications.rs b/src/client/applications.rs index 906bb9c..810da61 100644 --- a/src/client/applications.rs +++ b/src/client/applications.rs @@ -65,6 +65,15 @@ fn AddApplicationModal( required /> +