File size: 724 Bytes
caa70b1
 
 
 
 
 
 
 
 
 
 
 
e87131b
caa70b1
 
e87131b
caa70b1
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
"""POST endpoint — submit a new article."""
from fastapi import APIRouter, HTTPException

from database import supabase
from models import ArticleIn, ArticleOut

router = APIRouter(tags=["post"])


@router.post("", response_model=ArticleOut, status_code=201)
def create_article(article: ArticleIn):
    """Insert a new article into the knowledge base."""
    payload = article.model_dump(exclude_none=True)
    result = (
        supabase.table("articles")
        .insert(payload)
        .execute()
    )
    if not result.data:
        raise HTTPException(status_code=500, detail="Failed to insert article")
    row = result.data[0]
    return ArticleOut(id=row["id"], title=row["title"], created_at=row["created_at"])