75 lines
2.2 KiB
Rust
75 lines
2.2 KiB
Rust
use fathom_function::{chrono::NaiveDate, forms::deserialize_date, tracing};
|
|
use pipeline_application::{
|
|
application::{Application, CorrosionCouponInitialReport},
|
|
serialization::serialize_gram,
|
|
};
|
|
use serde::{Deserialize, Serialize};
|
|
use uom::si::f64::Mass;
|
|
use uuid::Uuid;
|
|
|
|
#[fathom_function::function]
|
|
async fn upload_corrosion_coupon_report(input: Input) -> Result<Output, String> {
|
|
let app = Application::new_from_compile_env(input.org_id, input.project_id).unwrap();
|
|
|
|
for (pipeline_id, coupon_retrieval_point_id) in input
|
|
.pipeline_id
|
|
.into_iter()
|
|
.zip(input.coupon_retrieval_point_id)
|
|
{
|
|
app.upload_corrosion_coupon_report(pipeline_id, coupon_retrieval_point_id, &input.report)
|
|
.await
|
|
.map_err(|err| {
|
|
tracing::error!(%pipeline_id, ?err, "Error uploading corrosion coupon report locations");
|
|
format!("{err:?}")
|
|
})?;
|
|
}
|
|
|
|
Ok(Output {
|
|
status: "Success".to_owned(),
|
|
})
|
|
}
|
|
|
|
#[derive(Debug, Serialize)]
|
|
struct Output {
|
|
status: String,
|
|
}
|
|
|
|
#[derive(Debug, Deserialize)]
|
|
struct Input {
|
|
org_id: Uuid,
|
|
project_id: String,
|
|
pipeline_id: Vec<Uuid>,
|
|
coupon_retrieval_point_id: Vec<Uuid>,
|
|
#[serde(flatten)]
|
|
report: Report,
|
|
}
|
|
|
|
#[derive(Debug, Deserialize)]
|
|
struct Report {
|
|
/// The date this corrosion coupon was installed in the pipeline.
|
|
#[serde(deserialize_with = "deserialize_date")]
|
|
installation_date: NaiveDate,
|
|
/// The date this corrosion coupon was removed from the pipeline.
|
|
#[serde(deserialize_with = "deserialize_date")]
|
|
retrieval_date: NaiveDate,
|
|
/// The metal loss of the coupon during the days exposed in the pipeline
|
|
#[serde(with = "serialize_gram")]
|
|
metal_loss: Mass,
|
|
/// The inspector name or identifier
|
|
inspector: String,
|
|
/// And additional remarks about the inspection
|
|
remarks: Option<String>,
|
|
}
|
|
|
|
impl From<&Report> for CorrosionCouponInitialReport {
|
|
fn from(value: &Report) -> Self {
|
|
Self {
|
|
installation_date: value.installation_date,
|
|
retrieval_date: value.retrieval_date,
|
|
metal_loss: value.metal_loss,
|
|
inspector: value.inspector.to_owned(),
|
|
remarks: value.remarks.to_owned(),
|
|
}
|
|
}
|
|
}
|