use fathom_function::tracing; use pipeline_application::application::{ Application, ElevationProvider as ApplicationElevationProvider, FileDetails as ApplicationFileDetails, }; use serde::{Deserialize, Serialize}; use uuid::Uuid; #[fathom_function::function] async fn pipeline_route(input: Input) -> Result { let elevation_provider = input.elevation_provider; let mut pipeline_ids = Vec::new(); let project_id = input.project_id.to_owned(); let org_id = input.org_id; let mut app = Application::new_from_compile_env(org_id, &project_id).unwrap(); // TODO: We need a solution for getting API keys into functions app.with_key() .map_box("pk.eyJ1IjoiaG11YmFpcmVlayIsImEiOiJjam03ZXh1cXcxdXV2M3FtdWl4dGphNmxhIn0.1V1fEZMzOt0YumJtwU9AvA".to_owned()) .google_maps("AIzaSyB3qwZNz9MfreHYtfp93zzmnsCDFBU4cso".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 .map_err(|err| { tracing::error!(%pipeline_id, ?err, "Error running pipeline route calculation"); format!("{err:?}") })?; } Ok(Output { pipeline_ids, org_id, project_id, }) } #[derive(Debug, Serialize)] struct Output { org_id: Uuid, project_id: String, pipeline_ids: Vec, } #[derive(Debug, Deserialize)] struct Input { org_id: Uuid, project_id: String, elevation_provider: ElevationProvider, pipeline_id: Vec, route_file: Vec, } impl Input { fn into_iter(self) -> impl Iterator { 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 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 for ApplicationFileDetails { fn from(value: FileDetails) -> Self { Self { id: value.file_id, revision_id: value.revision_id, } } }