use crate::domain::{Measurement, Region};
use crate::ports::IntensityRepository;
use super::ApplicationError;
pub struct GetCurrentIntensity<R: IntensityRepository> {
repository: R,
methodology_id: String,
}
impl<R: IntensityRepository> GetCurrentIntensity<R> {
pub fn new(repository: R, methodology_id: impl Into<String>) -> Self {
Self {
repository,
methodology_id: methodology_id.into(),
}
}
pub async fn execute(&self, region: Region) -> Result<Measurement, ApplicationError> {
self.repository
.latest(region, &self.methodology_id)
.await?
.ok_or(ApplicationError::NotFound(region))
}
pub async fn execute_all(&self) -> Result<Vec<Measurement>, ApplicationError> {
Ok(self.repository.latest_all(&self.methodology_id).await?)
}
}