85 lines
2.3 KiB
Rust
85 lines
2.3 KiB
Rust
use fathom_function::Context;
|
|
use pipeline_application::application::{
|
|
Application, ElevationProvider as ApplicationElevationProvider,
|
|
FileDetails as ApplicationFileDetails,
|
|
};
|
|
use serde::{Deserialize, Serialize};
|
|
use uuid::Uuid;
|
|
|
|
#[fathom_function::function(default(
|
|
org_id = "2cbfe270-d195-48ad-aed1-24145924635c",
|
|
project_id = "6807aed617c4295ab4a6aa78"
|
|
))]
|
|
async fn pipeline_route(context: Context, input: Input) -> Result<Output, String> {
|
|
let elevation_provider = input.elevation_provider;
|
|
let mut pipeline_ids = Vec::new();
|
|
let app = Application::new(context.env, context.org_id, &context.project_id).unwrap();
|
|
// TODO: We need a solution for getting API keys into functions
|
|
// app.with_key().map_box("".to_owned());
|
|
for (pipeline_id, file_details) in input.into_iter() {
|
|
pipeline_ids.push(pipeline_id);
|
|
|
|
app.process_pipeline_route_file(
|
|
pipeline_id,
|
|
file_details,
|
|
elevation_provider,
|
|
)
|
|
.await
|
|
.unwrap();
|
|
}
|
|
Ok(Output { pipeline_ids })
|
|
}
|
|
|
|
#[derive(Debug, Serialize)]
|
|
struct Output {
|
|
pipeline_ids: Vec<Uuid>
|
|
}
|
|
|
|
#[derive(Debug, Deserialize)]
|
|
struct Input {
|
|
elevation_provider: ElevationProvider,
|
|
pipeline_id: Vec<Uuid>,
|
|
route_file: Vec<FileDetails>,
|
|
}
|
|
|
|
impl Input {
|
|
fn into_iter(self) -> impl Iterator<Item = (Uuid, FileDetails)> {
|
|
self.pipeline_id.into_iter().zip(self.route_file)
|
|
}
|
|
}
|
|
|
|
#[derive(Debug, Clone, Copy, Deserialize)]
|
|
#[serde(rename_all = "snake_case")]
|
|
pub enum ElevationProvider {
|
|
OpenElevation,
|
|
Mapbox,
|
|
GoogleMaps,
|
|
}
|
|
|
|
impl From<ElevationProvider> for ApplicationElevationProvider {
|
|
fn from(value: ElevationProvider) -> Self {
|
|
match value {
|
|
ElevationProvider::OpenElevation => Self::OpenElevation,
|
|
ElevationProvider::Mapbox => Self::MapBox,
|
|
ElevationProvider::GoogleMaps => Self::GoogleMaps,
|
|
}
|
|
}
|
|
}
|
|
|
|
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
|
#[serde(rename_all = "camelCase")]
|
|
pub struct FileDetails {
|
|
pub file_id: Uuid,
|
|
pub revision_id: Uuid,
|
|
}
|
|
|
|
|
|
impl From<FileDetails> for ApplicationFileDetails {
|
|
fn from(value: FileDetails) -> Self {
|
|
Self {
|
|
id: value.file_id,
|
|
revision_id: value.revision_id,
|
|
}
|
|
}
|
|
}
|