30 lines
969 B
Python
30 lines
969 B
Python
from fastapi import APIRouter, Depends, HTTPException
|
|
from pydantic import BaseModel
|
|
|
|
from ...domain.services.article_service import ArticleService
|
|
from ...outbound.postgres.database import get_db, AsyncSessionLocal
|
|
from ...outbound.postgres.repositories.summarise_job_repository import PostgresSummariseJobRepository
|
|
|
|
|
|
router = APIRouter(prefix="/articles", tags=["articles"])
|
|
|
|
|
|
class ArticleResponse(BaseModel):
|
|
target_language: str
|
|
complexity_level: str
|
|
input_texts: list[str]
|
|
|
|
class ArticlesResponse(BaseModel):
|
|
articles: list[ArticleResponse]
|
|
|
|
@router.get("", response_model=ArticlesResponse, status_code=200)
|
|
async def get_articles(
|
|
db = Depends(get_db),
|
|
) -> ArticlesResponse:
|
|
service = ArticleService(PostgresSummariseJobRepository(db))
|
|
|
|
try:
|
|
articles = await service.get_all_articles()
|
|
return ArticlesResponse(articles=articles)
|
|
except Exception as e:
|
|
raise HTTPException(status_code=500, detail=str(e))
|