Allow passing in a store to handle_user_command

Signed-off-by: Olivier 'reivilibre <olivier@librepush.net>
This commit is contained in:
Olivier 'reivilibre' 2024-07-06 15:07:26 +01:00
parent d088af98d8
commit 67e7d6bf5f
2 changed files with 12 additions and 6 deletions

View File

@ -103,9 +103,14 @@ async fn main() -> eyre::Result<()> {
.await
.context("Failed to connect to Postgres")?;
let secrets = SecretConfig::try_new(&config).await?;
web::serve(bind, Arc::new(store), Arc::new(config), Arc::new(secrets)).await?
web::serve(bind, Arc::new(store), Arc::new(config), Arc::new(secrets)).await?;
}
Subcommand::User { cmd } => {
let store = IdCoopStore::connect(&config.postgres.connect)
.await
.context("Failed to connect to Postgres")?;
handle_user_command(cmd, &config, &store).await?;
}
Subcommand::User { cmd } => handle_user_command(cmd, &config).await?,
}
Ok(())

View File

@ -57,10 +57,11 @@ pub enum UserCommand {
}
/// Handles a user command from the command-line interface.
pub async fn handle_user_command(command: UserCommand, config: &Configuration) -> eyre::Result<()> {
let store = IdCoopStore::connect(&config.postgres.connect)
.await
.context("Failed to connect to Postgres")?;
pub async fn handle_user_command(
command: UserCommand,
config: &Configuration,
store: &IdCoopStore,
) -> eyre::Result<()> {
match command {
UserCommand::Add { username, locked } => {
store