reactive_graph_type_system_rest/
flows.rs

1use std::sync::Arc;
2
3use actix_web::HttpResponse;
4use actix_web::get;
5use actix_web::web;
6use mime::APPLICATION_JSON;
7
8use crate::json_schema_response;
9use reactive_graph_graph::FlowTypeId;
10use reactive_graph_type_system_api::FlowTypeManager;
11use reactive_graph_type_system_json_schema::flows::schema_flow_types;
12
13#[get("/types/flows")]
14pub async fn get_flow_types(flow_type_manager: web::Data<Arc<dyn FlowTypeManager + Send + Sync>>) -> HttpResponse {
15    HttpResponse::Ok().content_type(APPLICATION_JSON.to_string()).json(flow_type_manager.get_all())
16}
17
18#[get("/types/flows/{namespace}/{type_name}")]
19pub async fn get_flow_type(path: web::Path<(String, String)>, flow_type_manager: web::Data<Arc<dyn FlowTypeManager + Send + Sync>>) -> HttpResponse {
20    let (namespace, type_name) = path.into_inner();
21    let flow_ty = FlowTypeId::new_from_type(namespace, type_name);
22    match flow_type_manager.get(&flow_ty) {
23        Some(flow_type) => HttpResponse::Ok().content_type(APPLICATION_JSON.to_string()).json(&flow_type),
24        None => HttpResponse::NotFound()
25            .content_type(APPLICATION_JSON.to_string())
26            .body(format!("Flow Type {} not found", &flow_ty)),
27    }
28}
29
30#[get("/types/flows/schema")]
31pub async fn json_schema_flow_types() -> HttpResponse {
32    json_schema_response(schema_flow_types())
33}