|
@@ -41,7 +41,7 @@ class Post(PostBase):
|
|
|
class Config:
|
|
class Config:
|
|
|
from_attributes = True
|
|
from_attributes = True
|
|
|
|
|
|
|
|
-@router.get("/", response_model=List[Post])
|
|
|
|
|
|
|
+@router.get("", response_model=List[Post])
|
|
|
async def get_posts(published_only: bool = True):
|
|
async def get_posts(published_only: bool = True):
|
|
|
query = "SELECT * FROM posts"
|
|
query = "SELECT * FROM posts"
|
|
|
if published_only:
|
|
if published_only:
|
|
@@ -62,7 +62,7 @@ async def get_post(id_or_slug: str):
|
|
|
|
|
|
|
|
raise HTTPException(status_code=404, detail="Post not found")
|
|
raise HTTPException(status_code=404, detail="Post not found")
|
|
|
|
|
|
|
|
-@router.post("/", response_model=Post)
|
|
|
|
|
|
|
+@router.post("", response_model=Post)
|
|
|
async def create_post(post: PostCreate, request: Request, token: str = Depends(auth_utils.oauth2_scheme)):
|
|
async def create_post(post: PostCreate, request: Request, token: str = Depends(auth_utils.oauth2_scheme)):
|
|
|
payload = auth_utils.decode_token(token)
|
|
payload = auth_utils.decode_token(token)
|
|
|
if not payload or payload.get("role") != 'admin':
|
|
if not payload or payload.get("role") != 'admin':
|