diff options
Diffstat (limited to 'src/server/state/mod.rs')
| -rw-r--r-- | src/server/state/mod.rs | 17 |
1 files changed, 9 insertions, 8 deletions
diff --git a/src/server/state/mod.rs b/src/server/state/mod.rs index 0726689..f5f731e 100644 --- a/src/server/state/mod.rs +++ b/src/server/state/mod.rs @@ -1,33 +1,34 @@ pub mod database; +pub mod federation; + +use std::sync::Arc; use sellershut_auth::{ClientOptions, OauthClient}; -use sqlx::PgPool; #[cfg(feature = "oauth-discord")] use url::Url; -use crate::config::Config; #[cfg(feature = "oauth-discord")] use crate::config::DiscordOauth; +use crate::{config::Config, server::driver::SellershutDriver}; +#[derive(Clone)] pub struct AppState { - database: PgPool, + driver: Arc<dyn SellershutDriver>, #[cfg(feature = "oauth-discord")] oauth_discord: OauthClient, } impl AppState { - pub async fn new(config: &Config) -> anyhow::Result<Self> { - let database = database::connect(&config.database).await?; - + pub async fn new(config: &Config, driver: impl SellershutDriver) -> anyhow::Result<Self> { Ok(Self { - database, + driver: Arc::new(driver), oauth_discord: discord_client(&config.oauth.discord, &config.oauth.oauth_redirect_url)?, }) } } #[cfg(feature = "oauth-discord")] -fn discord_client(disc: &DiscordOauth, redirect: &Url)->anyhow::Result<OauthClient> { +fn discord_client(disc: &DiscordOauth, redirect: &Url) -> anyhow::Result<OauthClient> { let discord_opts = ClientOptions::builder() .client_id(disc.client_id.to_owned()) .redirect_url(redirect.to_string()) |
