bloom_web_core/lib.rs
1pub mod entity_registry;
2pub mod controller_registry;
3pub mod swagger_registry;
4pub mod scheduler_registry;
5pub mod logger;
6pub mod config;
7
8pub mod application;
9
10pub use entity_registry::*;
11pub use controller_registry::*;
12pub use swagger_registry::*;
13pub use scheduler_registry::*;
14pub use logger::*;
15pub use config::*;
16pub use application::*;
17
18pub use actix_web;
19pub use sqlx::{self, MySqlPool as Pool, MySql};
20pub use tokio;
21pub use serde;
22pub use serde_json;
23pub use anyhow;
24pub use log;
25
26/// Application builder for configuring and creating Bloom applications.
27///
28/// This struct provides a fluent API for configuring the Bloom web application
29/// with various settings like database URL, port, and feature flags.
30pub struct BloomApplication {
31 config: BloomConfig,
32}
33
34impl BloomApplication {
35 /// Creates a new BloomApplication with default configuration.
36 ///
37 /// # Returns
38 /// * `Self` - A new BloomApplication instance with default settings
39 pub fn new() -> Self {
40 Self {
41 config: BloomConfig::default(),
42 }
43 }
44
45 /// Configures the application with a custom BloomConfig.
46 ///
47 /// # Arguments
48 /// * `config` - The configuration to use for the application
49 ///
50 /// # Returns
51 /// * `Self` - The configured BloomApplication instance
52 pub fn with_config(mut self, config: BloomConfig) -> Self {
53 self.config = config;
54 self
55 }
56
57 /// Sets the database URL for the application.
58 ///
59 /// # Arguments
60 /// * `url` - The database connection URL
61 ///
62 /// # Returns
63 /// * `Self` - The configured BloomApplication instance
64 pub fn with_database_url(mut self, url: &str) -> Self {
65 self.config.database_url = Some(url.to_string());
66 self
67 }
68
69 /// Builds the configured application into a runnable BloomApp.
70 ///
71 /// # Returns
72 /// * `anyhow::Result<BloomApp>` - The built application or an error
73 pub async fn build(self) -> anyhow::Result<BloomApp> {
74 Ok(BloomApp {
75 config: self.config,
76 })
77 }
78}
79
80/// The main Bloom application that can be run to start the web server.
81///
82/// This struct represents a fully configured Bloom application that can be
83/// started to serve HTTP requests.
84pub struct BloomApp {
85 #[allow(dead_code)]
86 config: BloomConfig,
87}
88
89impl BloomApp {
90 /// Runs the Bloom application on the specified bind address.
91 ///
92 /// This method starts the web server and begins serving HTTP requests.
93 ///
94 /// # Arguments
95 /// * `_bind_address` - The address to bind the server to (currently unused)
96 ///
97 /// # Returns
98 /// * `anyhow::Result<()>` - Ok if the server runs successfully, Err otherwise
99 pub async fn run(self, _bind_address: &str) -> anyhow::Result<()> {
100 application::run().await
101 }
102}
103
104/// Configuration settings for the Bloom application.
105///
106/// This struct contains all the configuration parameters needed to run
107/// a Bloom application, including server settings and feature flags.
108#[derive(Clone, Debug)]
109pub struct BloomConfig {
110 pub host: String,
111 pub port: u16,
112 pub database_url: Option<String>,
113 pub enable_swagger: bool,
114}
115
116impl Default for BloomConfig {
117 /// Creates a default BloomConfig with sensible defaults.
118 ///
119 /// # Returns
120 /// * `Self` - A BloomConfig with default values
121 fn default() -> Self {
122 Self {
123 host: "127.0.0.1".to_string(),
124 port: 8080,
125 database_url: None,
126 enable_swagger: true,
127 }
128 }
129}