Fix cache bug

Fix bug where a potentially incorrect resolution would be assumed.
This commit is contained in:
2025-01-08 15:30:14 +01:00
parent 81ec482918
commit 96aabc8019
4 changed files with 84 additions and 27 deletions

30
src/cache/cache_line.rs vendored Normal file
View File

@@ -0,0 +1,30 @@
use chrono::serde::ts_seconds;
use chrono::{DateTime, Local, Utc};
use serde::{Deserialize, Serialize};
use crate::models::ExchangeRateResult;
#[derive(Serialize, Deserialize, Debug)]
pub struct CacheLine {
#[serde(with = "ts_seconds")]
date: DateTime<Utc>,
#[serde(rename = "camelCase")]
pub exchange_rate_results: Vec<ExchangeRateResult>,
}
impl CacheLine {
pub fn validate(&self) -> bool {
let today = Local::now().naive_local().date();
let saved = self.date.naive_local().date();
saved == today
}
pub fn new(exchange_rate_results: Vec<ExchangeRateResult>) -> Self {
let date = Local::now().to_utc();
Self {
exchange_rate_results,
date,
}
}
}