reactive_graph_type_system_rest/
entities.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::EntityTypeManager;
10use reactive_graph_type_system_json_schema::entities::schema_entity_types;
11
12#[get("/types/entities")]
13pub async fn get_entity_types(entity_type_manager: web::Data<Arc<dyn EntityTypeManager + Send + Sync>>) -> HttpResponse {
14 HttpResponse::Ok()
15 .content_type(APPLICATION_JSON.to_string())
16 .json(entity_type_manager.get_all())
17}
18
19#[get("/types/entities/{namespace}/{type_name}")]
20pub async fn get_entity_type(path: web::Path<(String, String)>, entity_type_manager: web::Data<Arc<dyn EntityTypeManager + Send + Sync>>) -> HttpResponse {
21 let (namespace, type_name) = path.into_inner();
22 match entity_type_manager.get_by_type(&namespace, &type_name) {
23 Some(entity_type) => HttpResponse::Ok().content_type(APPLICATION_JSON.to_string()).json(&entity_type),
24 None => HttpResponse::NotFound()
25 .content_type(APPLICATION_JSON.to_string())
26 .body(format!("Entity Type {namespace}__{type_name} not found")),
27 }
28}
29
30#[get("/types/entities/schema")]
31pub async fn json_schema_entity_types() -> HttpResponse {
32 json_schema_response(schema_entity_types())
33}