use std::sync::Arc;
use crate::operations::{Context, Operation};
use crate::storage::StorageManager;
use crate::{Error, Result};
use harmos_domain::model::storage::files::FileHash;
use harmos_domain::operations::storage::HashFile;
pub(super) struct Handler<C> {
storage: Arc<StorageManager<C>>,
}
impl<C: 'static> Operation for Handler<C> {
type Declaration = HashFile;
type Resources = StorageManager<C>;
type Error = Error;
type Context<'a> = Context<'a>;
type Endpoints = ();
async fn initialize<'ctx>(storage: Arc<StorageManager<C>>, _: Self::Context<'ctx>) -> Result<Self> {
Ok(Self { storage })
}
#[tracing::instrument(target = "harmos::storage", name = "storage.operation.hash_file", level = "trace", skip_all)]
async fn run<'a>(&mut self, _: Self::Context<'a>, request: &mut HashFile, _: &mut ()) -> Result<crate::operations::Response<FileHash>> {
Ok(self.storage.hash_file(request.clone()).await?.into())
}
fn classify(error: &Error) -> crate::operations::FailureKind {
super::classify(error)
}
}