Update code in endpoints/api/v1/endpoint.post.py
This commit is contained in:
parent
7bfb29d953
commit
37ee36baa3
49
endpoints/api/v1/endpoint.post.py
Normal file
49
endpoints/api/v1/endpoint.post.py
Normal file
@ -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"
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user