From 37ee36baa304e7fb880c109345e77137a30d58c5 Mon Sep 17 00:00:00 2001 From: Backend IM Bot Date: Wed, 19 Mar 2025 04:46:29 +0000 Subject: [PATCH] Update code in endpoints/api/v1/endpoint.post.py --- endpoints/api/v1/endpoint.post.py | 49 +++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 endpoints/api/v1/endpoint.post.py diff --git a/endpoints/api/v1/endpoint.post.py b/endpoints/api/v1/endpoint.post.py new file mode 100644 index 0000000..d280910 --- /dev/null +++ b/endpoints/api/v1/endpoint.post.py @@ -0,0 +1,49 @@ +from fastapi import APIRouter, Depends, HTTPException +from core.database import fake_users_db +import uuid +from typing import Optional +from pydantic import BaseModel + +router = APIRouter() + +class BlogPost(BaseModel): + title: str + content: str + author_id: Optional[str] = None + +@router.post("/posts") +async def create_blog_post( + post: BlogPost, + username: str = Depends(get_current_user_dummy) +): + """Create a new blog post""" + post_id = str(uuid.uuid4()) + + if username not in fake_users_db: + raise HTTPException(status_code=404, detail="User not found") + + # Simulate storing post in database + if "posts" not in fake_users_db: + fake_users_db["posts"] = {} + + fake_users_db["posts"][post_id] = { + "id": post_id, + "title": post.title, + "content": post.content, + "author": username, + "created_at": "2024-01-01T00:00:00Z" # Demo timestamp + } + + return { + "message": "Blog post created successfully", + "post_id": post_id, + "data": { + "title": post.title, + "author": username, + "created_at": "2024-01-01T00:00:00Z" + }, + "metadata": { + "word_count": len(post.content.split()), + "status": "published" + } + } \ No newline at end of file