From be7b830804bbb693ce9abd4e0c095f29ad10a4b9 Mon Sep 17 00:00:00 2001 From: Tal Leibman Date: Fri, 25 Dec 2020 19:23:46 +0200 Subject: [PATCH] collection.py: create --- etebase_fastapi/collection.py | 34 ++++++++++++++++++++++++++++++---- 1 file changed, 30 insertions(+), 4 deletions(-) diff --git a/etebase_fastapi/collection.py b/etebase_fastapi/collection.py index 7c9aca8..ba462c9 100644 --- a/etebase_fastapi/collection.py +++ b/etebase_fastapi/collection.py @@ -1,16 +1,16 @@ import typing as t +from asgiref.sync import sync_to_async from django.contrib.auth import get_user_model from django.db.models import Q from django.db.models import QuerySet -from fastapi import APIRouter, Depends +from fastapi import APIRouter, Depends, status from pydantic import BaseModel -from asgiref.sync import sync_to_async -from django_etebase.models import Collection, Stoken, AccessLevels, CollectionMember +from django_etebase.models import Collection, AccessLevels, CollectionMember from .authentication import get_authenticated_user from .msgpack import MsgpackRoute, MsgpackResponse -from .stoken_handler import filter_by_stoken_and_limit, filter_by_stoken, get_queryset_stoken +from .stoken_handler import filter_by_stoken_and_limit User = get_user_model() collection_router = APIRouter(route_class=MsgpackRoute) @@ -75,3 +75,29 @@ async def list_multi( ) response = await list_common(queryset, user, stoken, limit) return response + + +class CollectionItemContent(BaseModel): + uid: str + meta: bytes + deleted: bool + chunks: t.List[t.List[t.Union[str, bytes]]] + + +class Item(BaseModel): + uid: str + version: int + etag: t.Optional[str] + content: CollectionItemContent + + +class CollectionItemIn(BaseModel): + collectionType: bytes + collectionKey: bytes + item: Item + + +@collection_router.post("/") +def create(data: CollectionItemIn): + # FIXME save actual item + return MsgpackResponse({}, status_code=status.HTTP_201_CREATED)