-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(cli): add command to generate missing invoices
- Loading branch information
Showing
12 changed files
with
143 additions
and
5 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
use academy_config::Config; | ||
use academy_di::Provide; | ||
use academy_finance_contracts::FinanceService; | ||
use academy_persistence_contracts::{paypal::PaypalRepository, Database}; | ||
use clap::Subcommand; | ||
use futures::TryStreamExt; | ||
use indicatif::ProgressBar; | ||
|
||
use crate::{ | ||
cache, database, email, | ||
environment::{types, ConfigProvider, Provider}, | ||
}; | ||
|
||
#[derive(Debug, Subcommand)] | ||
pub enum AdminInvoiceCommand { | ||
/// Generate missing invoice pdf files | ||
#[command(aliases(["g"]))] | ||
Generate, | ||
} | ||
|
||
impl AdminInvoiceCommand { | ||
pub async fn invoke(self, config: Config) -> anyhow::Result<()> { | ||
match self { | ||
AdminInvoiceCommand::Generate => generate(config).await, | ||
} | ||
} | ||
} | ||
|
||
async fn generate(config: Config) -> anyhow::Result<()> { | ||
let database = database::connect(&config.database).await?; | ||
let cache = cache::connect(&config.cache).await?; | ||
let email_service = email::connect(&config.email).await?; | ||
let config_provider = ConfigProvider::new(&config)?; | ||
let mut provider = Provider::new(config_provider, database, cache, email_service); | ||
|
||
let db: types::Database = provider.provide(); | ||
let mut txn = db.begin_transaction().await?; | ||
|
||
let finance_service: types::Finance = provider.provide(); | ||
let paypal_repo: types::PaypalRepo = provider.provide(); | ||
|
||
let cnt = paypal_repo.count_coin_orders(&mut txn).await?; | ||
let bar = ProgressBar::new(cnt); | ||
let mut stream = std::pin::pin!(paypal_repo.stream_coin_orders(&mut txn)); | ||
let mut txn = db.begin_transaction().await?; | ||
while let Some(coin_order) = stream.try_next().await? { | ||
finance_service | ||
.get_invoice_pdf(&mut txn, coin_order.invoice_number) | ||
.await?; | ||
bar.inc(1); | ||
} | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,32 @@ | ||
use academy_config::Config; | ||
use clap::Subcommand; | ||
use invoice::AdminInvoiceCommand; | ||
use user::AdminUserCommand; | ||
|
||
mod invoice; | ||
mod user; | ||
|
||
#[derive(Debug, Subcommand)] | ||
pub enum AdminCommand { | ||
/// Manager user accounts | ||
/// Manage user accounts | ||
#[command(aliases(["u"]))] | ||
User { | ||
#[command(subcommand)] | ||
command: AdminUserCommand, | ||
}, | ||
/// Manage invoices | ||
#[command(aliases(["i"]))] | ||
Invoice { | ||
#[command(subcommand)] | ||
command: AdminInvoiceCommand, | ||
}, | ||
} | ||
|
||
impl AdminCommand { | ||
pub async fn invoke(self, config: Config) -> anyhow::Result<()> { | ||
match self { | ||
AdminCommand::User { command } => command.invoke(config).await, | ||
AdminCommand::Invoice { command } => command.invoke(config).await, | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters