1818from .models .errored_models import ErroredRequestModel , ErroredResponseModel
1919from .controller .errored_state import errored_state
2020
21+ from .models .graph_models import UpsertGraphTemplateRequest , UpsertGraphTemplateResponse
22+ from .controller .upsert_graph_template import upsert_graph_template as upsert_graph_template_controller
23+
2124
2225
2326logger = LogsManager ().get_logger ()
2427
25- router = APIRouter (prefix = "/v0/namespace/{namespace_name}/states " , tags = ["state" ])
28+ router = APIRouter (prefix = "/v0/namespace/{namespace_name}" , tags = ["state" ])
2629
2730
2831@router .post (
29- "/enqueue" ,
32+ "/states/ enqueue" ,
3033 response_model = EnqueueResponseModel ,
3134 status_code = status .HTTP_200_OK ,
3235 response_description = "State enqueued on node queue successfully"
@@ -45,7 +48,7 @@ async def enqueue_state(namespace_name: str, body: EnqueueRequestModel, request:
4548
4649
4750@router .post (
48- "/create" ,
51+ "/states/ create" ,
4952 response_model = CreateResponseModel ,
5053 status_code = status .HTTP_200_OK ,
5154 response_description = "States created successfully"
@@ -64,7 +67,7 @@ async def create_state(namespace_name: str, body: CreateRequestModel, request: R
6467
6568
6669@router .post (
67- "/{state_id}/executed" ,
70+ "/states/ {state_id}/executed" ,
6871 response_model = ExecutedResponseModel ,
6972 status_code = status .HTTP_200_OK ,
7073 response_description = "State executed successfully"
@@ -83,7 +86,7 @@ async def executed_state_route(namespace_name: str, state_id: str, body: Execute
8386
8487
8588@router .post (
86- "/{state_id}/errored" ,
89+ "/states/ {state_id}/errored" ,
8790 response_model = ErroredResponseModel ,
8891 status_code = status .HTTP_200_OK ,
8992 response_description = "State errored successfully"
@@ -98,4 +101,22 @@ async def errored_state_route(namespace_name: str, state_id: str, body: ErroredR
98101 logger .error (f"API key is invalid for namespace { namespace_name } " , x_exosphere_request_id = x_exosphere_request_id )
99102 raise HTTPException (status_code = status .HTTP_401_UNAUTHORIZED , detail = "Invalid API key" )
100103
101- return await errored_state (namespace_name , ObjectId (state_id ), body , x_exosphere_request_id )
104+ return await errored_state (namespace_name , ObjectId (state_id ), body , x_exosphere_request_id )
105+
106+
107+ @router .put (
108+ "/graph-templates/{graph_name}" ,
109+ response_model = UpsertGraphTemplateResponse ,
110+ status_code = status .HTTP_200_OK ,
111+ response_description = "Graph template upserted successfully"
112+ )
113+ async def upsert_graph_template (namespace_name : str , graph_name : str , body : UpsertGraphTemplateRequest , request : Request , api_key : str = Depends (check_api_key )):
114+ x_exosphere_request_id = getattr (request .state , "x_exosphere_request_id" , str (uuid4 ()))
115+
116+ if api_key :
117+ logger .info (f"API key is valid for namespace { namespace_name } " , x_exosphere_request_id = x_exosphere_request_id )
118+ else :
119+ logger .error (f"API key is invalid for namespace { namespace_name } " , x_exosphere_request_id = x_exosphere_request_id )
120+ raise HTTPException (status_code = status .HTTP_401_UNAUTHORIZED , detail = "Invalid API key" )
121+
122+ return await upsert_graph_template_controller (namespace_name , graph_name , body , x_exosphere_request_id )
0 commit comments