Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,7 @@ docker-compose up -d
[x] Database Connection and ORM Setup

[x] Running with Uvicorn

[] Text Analysis Endpoints
[x] Text Analysis Endpoints

[] Testing the API

Expand Down
14 changes: 12 additions & 2 deletions api/app/api/endpoints/text_analysis.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
"""API endpoint for text analysis."""
from fastapi import APIRouter, Depends
from fastapi import APIRouter, Depends, HTTPException
from sqlalchemy.orm import Session
from sqlalchemy.exc import SQLAlchemyError

from app.api.dependencies import get_db
from app.schemas.text import TextAnalysisRequest, TextAnalysisResponse
from app.services.text_analysis import analyze_text
Expand All @@ -17,4 +19,12 @@ async def analyze(request: TextAnalysisRequest, db: Session = Depends(get_db)):
Returns a detailed analysis of the text, including word analysis, phrase analysis,
and overall AI likelihood.
"""
return analyze_text(request.text, db)
if not request.text.strip():
raise HTTPException(status_code=400, detail="Text must not be empty")

try:
return analyze_text(request.text, db)
except SQLAlchemyError as exc: # pragma: no cover - defensive
raise HTTPException(status_code=500, detail="Database error") from exc
except ValueError as exc:
raise HTTPException(status_code=400, detail=str(exc)) from exc
Loading