reactive_graph_type_system_rest/
components.rs1use 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_type_system_api::ComponentManager;
10use reactive_graph_type_system_json_schema::components::schema_components;
11
12#[get("/types/components")]
13pub async fn get_components(component_manager: web::Data<Arc<dyn ComponentManager + Send + Sync>>) -> HttpResponse {
14 HttpResponse::Ok().content_type(APPLICATION_JSON.to_string()).json(component_manager.get_all())
15}
16
17#[get("/types/components/{namespace}/{type_name}")]
18pub async fn get_component(path: web::Path<(String, String)>, component_manager: web::Data<Arc<dyn ComponentManager + Send + Sync>>) -> HttpResponse {
19 let (namespace, type_name) = path.into_inner();
20 match component_manager.get_by_type(&namespace, &type_name) {
21 Some(component) => HttpResponse::Ok().content_type(APPLICATION_JSON.to_string()).json(&component),
22 None => HttpResponse::NotFound()
23 .content_type(APPLICATION_JSON.to_string())
24 .body(format!("Component {namespace}__{type_name} not found")),
25 }
26}
27
28#[get("/types/components/schema")]
29pub async fn json_schema_components() -> HttpResponse {
30 json_schema_response(schema_components())
31}