From ee4e7cf498657ee78d3dbac6f8078085b2abc64d Mon Sep 17 00:00:00 2001 From: Tom Hacohen Date: Mon, 28 Dec 2020 09:11:35 +0200 Subject: [PATCH] Unify the nested router prefix. --- etebase_fastapi/app.py | 5 +++-- etebase_fastapi/collection.py | 12 ++++++------ etebase_fastapi/member.py | 10 ++++------ 3 files changed, 13 insertions(+), 14 deletions(-) diff --git a/etebase_fastapi/app.py b/etebase_fastapi/app.py index ffea2fb..a8b12d0 100644 --- a/etebase_fastapi/app.py +++ b/etebase_fastapi/app.py @@ -21,10 +21,11 @@ from .msgpack import MsgpackResponse app = FastAPI() VERSION = "v1" BASE_PATH = f"/api/{VERSION}" +COLLECTION_UID_MARKER = "{collection_uid}" app.include_router(authentication_router, prefix=f"{BASE_PATH}/authentication") app.include_router(collection_router, prefix=f"{BASE_PATH}/collection") -app.include_router(item_router, prefix=f"{BASE_PATH}/collection") -app.include_router(member_router, prefix=f"{BASE_PATH}/collection") +app.include_router(item_router, prefix=f"{BASE_PATH}/collection/{COLLECTION_UID_MARKER}") +app.include_router(member_router, prefix=f"{BASE_PATH}/collection/{COLLECTION_UID_MARKER}") app.include_router(invitation_incoming_router, prefix=f"{BASE_PATH}/invitation/incoming") app.include_router(invitation_outgoing_router, prefix=f"{BASE_PATH}/invitation/outgoing") if settings.DEBUG: diff --git a/etebase_fastapi/collection.py b/etebase_fastapi/collection.py index ead113a..c0efed1 100644 --- a/etebase_fastapi/collection.py +++ b/etebase_fastapi/collection.py @@ -379,7 +379,7 @@ def item_create(item_model: CollectionItemIn, collection: models.Collection, val return instance -@item_router.get("/{collection_uid}/item/{item_uid}/") +@item_router.get("/item/{item_uid}/") def item_get( item_uid: str, queryset: QuerySet = Depends(get_item_queryset), @@ -408,7 +408,7 @@ def item_list_common( return MsgpackResponse(content=ret) -@item_router.get("/{collection_uid}/item/") +@item_router.get("/item/") async def item_list( queryset: QuerySet = Depends(get_item_queryset), stoken: t.Optional[str] = None, @@ -440,7 +440,7 @@ def item_bulk_common(data: ItemBatchIn, user: User, stoken: t.Optional[str], uid return MsgpackResponse({}) -@item_router.get("/{collection_uid}/item/{item_uid}/revision/") +@item_router.get("/item/{item_uid}/revision/") def item_revisions( item_uid: str, limit: int = 50, @@ -476,7 +476,7 @@ def item_revisions( return MsgpackResponse(ret) -@item_router.post("/{collection_uid}/item/fetch_updates/") +@item_router.post("/item/fetch_updates/") def fetch_updates( data: t.List[CollectionItemBulkGetIn], stoken: t.Optional[str] = None, @@ -510,14 +510,14 @@ def fetch_updates( return MsgpackResponse(ret) -@item_router.post("/{collection_uid}/item/transaction/", dependencies=[Depends(has_write_access)]) +@item_router.post("/item/transaction/", dependencies=[Depends(has_write_access)]) def item_transaction( collection_uid: str, data: ItemBatchIn, stoken: t.Optional[str] = None, user: User = Depends(get_authenticated_user) ): return item_bulk_common(data, user, stoken, collection_uid, validate_etag=True) -@item_router.post("/{collection_uid}/item/batch/", dependencies=[Depends(has_write_access)]) +@item_router.post("/item/batch/", dependencies=[Depends(has_write_access)]) def item_batch( collection_uid: str, data: ItemBatchIn, stoken: t.Optional[str] = None, user: User = Depends(get_authenticated_user) ): diff --git a/etebase_fastapi/member.py b/etebase_fastapi/member.py index af349d1..2c9b631 100644 --- a/etebase_fastapi/member.py +++ b/etebase_fastapi/member.py @@ -49,9 +49,7 @@ class MemberListResponse(BaseModel): done: bool -@member_router.get( - "/{collection_uid}/member/", response_model=MemberListResponse, dependencies=[Depends(verify_collection_admin)] -) +@member_router.get("/member/", response_model=MemberListResponse, dependencies=[Depends(verify_collection_admin)]) def member_list( iterator: t.Optional[str] = None, limit: int = 50, @@ -72,7 +70,7 @@ def member_list( @member_router.delete( - "/{collection_uid}/member/{username}/", + "/member/{username}/", status_code=status.HTTP_204_NO_CONTENT, dependencies=[Depends(verify_collection_admin)], ) @@ -83,7 +81,7 @@ def member_delete( @member_router.patch( - "/{collection_uid}/member/{username}/", + "/member/{username}/", status_code=status.HTTP_204_NO_CONTENT, dependencies=[Depends(verify_collection_admin)], ) @@ -100,7 +98,7 @@ def member_patch( @member_router.post( - "/{collection_uid}/member/leave/", + "/member/leave/", status_code=status.HTTP_204_NO_CONTENT, ) def member_leave(user: User = Depends(get_authenticated_user), collection: models.Collection = Depends(get_collection)):