Skip to content

Commit

Permalink
Implementing Platform endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
sagojez committed Apr 30, 2024
1 parent e20cc1f commit aa807e8
Show file tree
Hide file tree
Showing 7 changed files with 83 additions and 8 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ futures-util = "0.3.28"
handlebars = "4.4.0"
http = "1.1.0"
http-serde-ext = "1.0.2"
integrationos-domain = "3.0.1"
integrationos-domain = "3.0.3"
js-sandbox-ios = "0.1.0"
jsonpath_lib = "0.3.0"
jsonwebtoken = "8.3.0"
Expand Down
1 change: 1 addition & 0 deletions api/src/endpoints/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ pub mod oauth;
pub mod openapi;
pub mod passthrough;
pub mod pipeline;
pub mod platform;
pub mod transactions;
pub mod unified;

Expand Down
72 changes: 72 additions & 0 deletions api/src/endpoints/platform.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
use super::{create, delete, read, update, CrudHook, CrudRequest};
use crate::server::{AppState, AppStores};
use axum::{
routing::{patch, post},
Router,
};
use integrationos_domain::{
algebra::MongoStore,
id::{prefix::IdPrefix, Id},
ownership::Owners,
PlatformData,
};
use mongodb::bson::doc;
use serde::{Deserialize, Serialize};
use std::sync::Arc;

pub fn get_router() -> Router<Arc<AppState>> {
Router::new()
.route(
"/",
post(create::<CreateRequest, PlatformData>).get(read::<CreateRequest, PlatformData>),
)
.route(
"/:id",
patch(update::<CreateRequest, PlatformData>)
.delete(delete::<CreateRequest, PlatformData>),
)
}

#[derive(Debug, Clone, Eq, PartialEq, Deserialize, Serialize)]
#[cfg_attr(feature = "dummy", derive(fake::Dummy))]
#[serde(rename_all = "camelCase")]
pub struct CreateRequest {
pub connection_definition_id: Id,
pub name: String,
pub url: String,
pub version: String,
pub ownership: Owners,
pub analyzed: bool,
}

impl CrudHook<PlatformData> for CreateRequest {}

impl CrudRequest for CreateRequest {
type Output = PlatformData;

fn output(&self) -> Option<Self::Output> {
Some(Self::Output {
id: Id::now(IdPrefix::Platform),
connection_definition_id: self.connection_definition_id,
name: self.name.clone(),
url: self.url.clone(),
platform_version: self.version.clone(),
ownership: self.ownership.clone(),
analyzed: self.analyzed,
record_metadata: Default::default(),
})
}

fn update(&self, record: &mut Self::Output) {
record.connection_definition_id = self.connection_definition_id;
record.name = self.name.clone();
record.url = self.url.clone();
record.platform_version = self.version.clone();
record.ownership = self.ownership.clone();
record.analyzed = self.analyzed;
}

fn get_store(stores: AppStores) -> MongoStore<Self::Output> {
stores.platform.clone()
}
}
3 changes: 2 additions & 1 deletion api/src/routes/private.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::{
endpoints::{
common_model, connection_definition,
connection_model_definition::{self, test_connection_model_definition},
connection_model_schema, connection_oauth_definition, openapi,
connection_model_schema, connection_oauth_definition, openapi, platform,
},
middleware::jwt_auth::{self, JwtState},
server::AppState,
Expand Down Expand Up @@ -34,6 +34,7 @@ pub async fn get_router(state: &Arc<AppState>) -> Router<Arc<AppState>> {
"/connection-model-schemas",
connection_model_schema::get_router(),
)
.nest("/platforms", platform::get_router())
.nest("/common-models", common_model::get_router());

routes
Expand Down
4 changes: 1 addition & 3 deletions api/src/routes/protected.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ use crate::{
},
server::AppState,
};
use axum::{
error_handling::HandleErrorLayer, middleware::from_fn_with_state, Router,
};
use axum::{error_handling::HandleErrorLayer, middleware::from_fn_with_state, Router};
use http::HeaderName;
use std::{iter::once, sync::Arc};
use tower::{filter::FilterLayer, ServiceBuilder};
Expand Down
5 changes: 4 additions & 1 deletion api/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use integrationos_domain::{
cursor::Cursor,
event_access::EventAccess,
stage::Stage,
Connection, Event, Pipeline, Store, Transaction,
Connection, Event, Pipeline, PlatformData, Store, Transaction,
};
use moka::future::Cache;
use mongodb::{options::UpdateOptions, Client, Database};
Expand All @@ -42,6 +42,7 @@ pub struct AppStores {
pub common_enum: MongoStore<CommonEnum>,
pub connection: MongoStore<Connection>,
pub public_connection_details: MongoStore<PublicConnectionDetails>,
pub platform: MongoStore<PlatformData>,
pub settings: MongoStore<Settings>,
pub connection_config: MongoStore<ConnectionDefinition>,
pub pipeline: MongoStore<Pipeline>,
Expand Down Expand Up @@ -101,6 +102,7 @@ impl Server {
let common_model = MongoStore::new(&db, &Store::CommonModels).await?;
let common_enum = MongoStore::new(&db, &Store::CommonEnums).await?;
let connection = MongoStore::new(&db, &Store::Connections).await?;
let platform = MongoStore::new(&db, &Store::Platforms).await?;
let public_connection_details =
MongoStore::new(&db, &Store::PublicConnectionDetails).await?;
let settings = MongoStore::new(&db, &Store::Settings).await?;
Expand All @@ -127,6 +129,7 @@ impl Server {
frontend_oauth_config,
model_schema,
public_model_schema,
platform,
settings,
common_model,
common_enum,
Expand Down

0 comments on commit aa807e8

Please sign in to comment.