1818
1919from .auth import UserInDB , get_current_active_user
2020
21- router = APIRouter ()
21+ read_router = APIRouter ()
22+ write_router = APIRouter ()
2223
2324
2425repository = NodeRepository [orm .Node , orm .Node .Model ](orm .Node )
2526model_registry = NodeModelRegistry ()
2627
2728
28- @router .get ('/nodes/schema' )
29+ @read_router .get ('/nodes/schema' )
2930async def get_nodes_schema (
3031 which : t .Literal ['get' , 'post' ] | None = Query (
3132 None ,
@@ -57,7 +58,7 @@ def generate_create_models() -> dict[str, dict[str, t.Any]]:
5758 )
5859
5960
60- @router .get ('/nodes/projectable_properties' )
61+ @read_router .get ('/nodes/projectable_properties' )
6162@with_dbenv ()
6263async def get_node_projectable_properties () -> list [str ]:
6364 """Get projectable properties for AiiDA nodes.
@@ -67,7 +68,7 @@ async def get_node_projectable_properties() -> list[str]:
6768 return repository .get_projectable_properties ()
6869
6970
70- @router .get ('/nodes/download_formats' )
71+ @read_router .get ('/nodes/download_formats' )
7172async def get_nodes_download_formats () -> dict [str , t .Any ]:
7273 """Get download formats for AiiDA nodes.
7374
@@ -76,7 +77,7 @@ async def get_nodes_download_formats() -> dict[str, t.Any]:
7677 return resources .get_all_download_formats ()
7778
7879
79- @router .get (
80+ @read_router .get (
8081 '/nodes' ,
8182 response_model = PaginatedResults [orm .Node .Model ],
8283 response_model_exclude_none = True ,
@@ -93,7 +94,7 @@ async def get_nodes(
9394 return repository .get_entities (queries )
9495
9596
96- @router .get ('/nodes/types' )
97+ @read_router .get ('/nodes/types' )
9798async def get_nodes_types () -> list :
9899 """
99100 Return all node types in a machine-actionable format:
@@ -123,7 +124,7 @@ async def get_nodes_types() -> list:
123124 ]
124125
125126
126- @router .get (
127+ @read_router .get (
127128 '/nodes/types/{node_type}' ,
128129 response_model = PaginatedResults [orm .Node .Model ],
129130 response_model_exclude_none = True ,
@@ -149,7 +150,7 @@ async def get_nodes_by_type(
149150 raise HTTPException (status_code = 400 , detail = str (exception )) from exception
150151
151152
152- @router .get ('/nodes/types/{node_type}/projectable_properties' )
153+ @read_router .get ('/nodes/types/{node_type}/projectable_properties' )
153154@with_dbenv ()
154155async def get_node_class_projectable_properties (node_type : str ) -> list [str ]:
155156 """Get projectable properties of a given AiiDA node class.
@@ -166,7 +167,7 @@ async def get_node_class_projectable_properties(node_type: str) -> list[str]:
166167 raise HTTPException (status_code = 400 , detail = str (exception )) from exception
167168
168169
169- @router .get ('/nodes/types/{node_type}/schema' )
170+ @read_router .get ('/nodes/types/{node_type}/schema' )
170171async def get_node_class_schema (
171172 node_type : str ,
172173 which : t .Literal ['get' , 'post' ] | None = Query (
@@ -199,7 +200,7 @@ async def get_node_class_schema(
199200 raise HTTPException (status_code = 404 , detail = 'Parameter "which" must be either "get" or "post"' )
200201
201202
202- @router .get (
203+ @read_router .get (
203204 '/nodes/{node_id}' ,
204205 response_model = orm .Node .Model ,
205206 response_model_exclude_none = True ,
@@ -218,7 +219,7 @@ async def get_node(node_id: int) -> orm.Node.Model:
218219 raise HTTPException (status_code = 404 , detail = f'Could not find any Node with id { node_id } ' )
219220
220221
221- @router .get ('/nodes/{node_id}/download' )
222+ @read_router .get ('/nodes/{node_id}/download' )
222223@with_dbenv ()
223224async def download_node (
224225 node_id : int ,
@@ -269,7 +270,7 @@ def stream() -> t.Generator[bytes, None, None]:
269270 )
270271
271272
272- @router .get ('/nodes/{node_id}/repo/contents' )
273+ @write_router .get ('/nodes/{node_id}/repo/contents' )
273274@with_dbenv ()
274275async def get_node_repo_file_contents (
275276 node_id : int ,
@@ -315,7 +316,7 @@ def zip_stream() -> t.Generator[bytes, None, None]:
315316 return StreamingResponse (zip_stream (), media_type = 'application/zip' )
316317
317318
318- @router .post (
319+ @write_router .post (
319320 '/nodes' ,
320321 response_model = orm .Node .Model ,
321322 response_model_exclude_none = True ,
@@ -342,7 +343,7 @@ async def create_node(
342343
343344
344345# TODO what about folderdata?
345- @router .post (
346+ @write_router .post (
346347 '/nodes/file-upload' ,
347348 response_model = orm .Node .Model ,
348349 response_model_exclude_none = True ,
0 commit comments