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