drafts: Add an API endpoint for fetching drafts.

This endpoint will allow a user to fetch their drafts.

Signed-off-by: Hemanth V. Alluri <hdrive1999@gmail.com>
This commit is contained in:
Hemanth V. Alluri
2020-07-24 00:53:17 +05:30
committed by Tim Abbott
parent 630fd10be1
commit 21c9adbb3c
3 changed files with 74 additions and 1 deletions

View File

@@ -84,6 +84,11 @@ def further_validated_draft_dict(draft_dict: Dict[str, Any],
"last_edit_time": last_edit_time,
}
def fetch_drafts(request: HttpRequest, user_profile: UserProfile) -> HttpResponse:
user_drafts = Draft.objects.filter(user_profile=user_profile).order_by("last_edit_time")
draft_dicts = {draft.id: draft.to_dict() for draft in user_drafts}
return json_success({"count": user_drafts.count(), "drafts": draft_dicts})
@has_request_variables
def create_drafts(request: HttpRequest, user_profile: UserProfile,
draft_dicts: List[Dict[str, Any]]=REQ("drafts",