2121
2222from .auth import UserInDB , get_current_active_user
2323
24- router = APIRouter ()
24+ read_router = APIRouter ()
25+ write_router = APIRouter ()
2526
2627repository = NodeRepository [orm .Node , orm .Node .Model ](orm .Node )
2728model_registry = NodeModelRegistry ()
3435 NodeModelUnion = model_registry .ModelUnion
3536
3637
37- @router .get ('/nodes/schema' )
38+ @read_router .get ('/nodes/schema' )
3839async def get_nodes_schema (
3940 node_type : str | None = Query (
4041 None ,
@@ -63,7 +64,7 @@ async def get_nodes_schema(
6364 raise HTTPException (status_code = 422 , detail = str (exception )) from exception
6465
6566
66- @router .get ('/nodes/projectable_properties' )
67+ @read_router .get ('/nodes/projectable_properties' )
6768@with_dbenv ()
6869async def get_node_projectable_properties (
6970 node_type : str | None = Query (
@@ -84,7 +85,7 @@ async def get_node_projectable_properties(
8485 raise HTTPException (status_code = 422 , detail = str (err )) from err
8586
8687
87- @router .get ('/nodes/download_formats' )
88+ @read_router .get ('/nodes/download_formats' )
8889async def get_nodes_download_formats () -> dict [str , t .Any ]:
8990 """Get download formats for AiiDA nodes.
9091
@@ -100,7 +101,7 @@ async def get_nodes_download_formats() -> dict[str, t.Any]:
100101 raise HTTPException (status_code = 500 , detail = str (err )) from err
101102
102103
103- @router .get (
104+ @read_router .get (
104105 '/nodes' ,
105106 response_model = PaginatedResults [orm .Node .Model ],
106107 response_model_exclude_none = True ,
@@ -128,7 +129,7 @@ class NodeType(pdt.BaseModel):
128129 node_schema : str = pdt .Field (description = 'The URL to access the schema of this node type.' )
129130
130131
131- @router .get ('/nodes/types' , response_model = list [NodeType ])
132+ @read_router .get ('/nodes/types' , response_model = list [NodeType ])
132133async def get_node_types () -> list :
133134 """Get all node types in machine-actionable format.
134135
@@ -159,7 +160,7 @@ async def get_node_types() -> list:
159160 ]
160161
161162
162- @router .get (
163+ @read_router .get (
163164 '/nodes/{node_id}' ,
164165 response_model = orm .Node .Model ,
165166 response_model_exclude_none = True ,
@@ -182,7 +183,7 @@ async def get_node(node_id: int) -> orm.Node.Model:
182183 raise HTTPException (status_code = 500 , detail = str (err )) from err
183184
184185
185- @router .get (
186+ @read_router .get (
186187 '/nodes/{node_id}/attributes' ,
187188 response_model = dict [str , t .Any ],
188189)
@@ -203,7 +204,7 @@ async def get_node_attributes(node_id: int) -> dict[str, t.Any]:
203204 raise HTTPException (status_code = 500 , detail = str (err )) from err
204205
205206
206- @router .get (
207+ @read_router .get (
207208 '/nodes/{node_id}/extras' ,
208209 response_model = dict [str , t .Any ],
209210)
@@ -224,7 +225,7 @@ async def get_node_extras(node_id: int) -> dict[str, t.Any]:
224225 raise HTTPException (status_code = 500 , detail = str (err )) from err
225226
226227
227- @router .get ('/nodes/{node_id}/download' )
228+ @read_router .get ('/nodes/{node_id}/download' )
228229@with_dbenv ()
229230async def download_node (
230231 node_id : int ,
@@ -307,7 +308,7 @@ class RepoDirMetadata(pdt.BaseModel):
307308MetadataType = t .Union [RepoFileMetadata , RepoDirMetadata ]
308309
309310
310- @router .get (
311+ @read_router .get (
311312 '/nodes/{node_id}/repo/metadata' ,
312313 response_model = dict [str , MetadataType ],
313314)
@@ -328,7 +329,7 @@ async def get_node_repo_file_metadata(node_id: int) -> dict[str, dict]:
328329 raise HTTPException (status_code = 500 , detail = str (err )) from err
329330
330331
331- @router .get ('/nodes/{node_id}/repo/contents' )
332+ @read_router .get ('/nodes/{node_id}/repo/contents' )
332333@with_dbenv ()
333334async def get_node_repo_file_contents (
334335 node_id : int ,
@@ -384,7 +385,7 @@ def zip_stream() -> t.Generator[bytes, None, None]:
384385 return StreamingResponse (zip_stream (), media_type = 'application/zip' , headers = headers )
385386
386387
387- @router .post (
388+ @write_router .post (
388389 '/nodes' ,
389390 response_model = orm .Node .Model ,
390391 response_model_exclude_none = True ,
@@ -411,7 +412,7 @@ async def create_node(
411412 raise HTTPException (status_code = 500 , detail = str (exception )) from exception
412413
413414
414- @router .post (
415+ @write_router .post (
415416 '/nodes/file-upload' ,
416417 response_model = orm .Node .Model ,
417418 response_model_exclude_none = True ,
0 commit comments