use crate::application::error::ApplicationError;
use crate::domain::aggregates::resource_usage::{entity::ResourceUsage, value_objects::UsageId};
use crate::domain::ports::repositories::{RepositoryError, ResourceUsageRepository};
use std::sync::Arc;
pub struct GetResourceUsageByIdUseCase<R: ResourceUsageRepository> {
repository: Arc<R>,
}
impl<R: ResourceUsageRepository> GetResourceUsageByIdUseCase<R> {
pub fn new(repository: Arc<R>) -> Self {
Self { repository }
}
pub async fn execute(&self, id: &UsageId) -> Result<ResourceUsage, ApplicationError> {
self.repository
.find_by_id(id)
.await?
.ok_or(ApplicationError::Repository(RepositoryError::NotFound))
}
}