Make number of days configurable for transactions

This commit is contained in:
2026-05-25 23:15:20 +02:00
parent da0d80f4f4
commit 415a1f8684
3 changed files with 27 additions and 9 deletions
+12 -3
View File
@@ -26,6 +26,14 @@ impl Client {
.bearer_auth(&self.token)
.send()
.await?;
if !res.status().is_success() {
let code = res.status().as_u16();
let message = res.status().canonical_reason().unwrap_or("unknown");
return Err(Error::ApiError {
status: code,
message: message.to_string(),
});
}
let text = res.text().await?;
Ok(text)
}
@@ -121,8 +129,9 @@ impl Plan {
pub async fn list_transactions(
&self,
account_id: Option<&str>,
days: i64,
) -> Result<Vec<Transaction>, Error> {
let since_date = chrono::Local::now().date_naive() - chrono::Duration::days(30);
let since_date = chrono::Local::now().date_naive() - chrono::Duration::days(days);
let since_date = since_date.format("%Y-%m-%d");
let url = format!("plans/{}/transactions?since_date={}", self.id, since_date);
let raw = self.client.get(&url).await?;
@@ -166,8 +175,8 @@ impl Account {
})
}
pub async fn list_transactions(&self) -> Result<Vec<Transaction>, Error> {
self.plan.list_transactions(Some(&self.id)).await
pub async fn list_transactions(&self, days: i64) -> Result<Vec<Transaction>, Error> {
self.plan.list_transactions(Some(&self.id), days).await
}
pub async fn upload(&self, transactions: &[Transaction]) -> Result<(), Error> {