forked from Anteros-Code-Mentoria/poc-mvc-ocr
27 lines
611 B
Python
27 lines
611 B
Python
from fastapi import APIRouter, Depends
|
|
from sqlalchemy.orm import Session
|
|
from models.ocr_result import OCRResult
|
|
from database import SessionLocal
|
|
import uuid
|
|
|
|
router = APIRouter(prefix="/ocr", tags=["OCR"])
|
|
|
|
def get_db():
|
|
db = SessionLocal()
|
|
try:
|
|
yield db
|
|
finally:
|
|
db.close()
|
|
|
|
@router.post("/")
|
|
def create_ocr(documento_id: uuid.UUID, db: Session = Depends(get_db)):
|
|
ocr = OCRResult(documento_id=documento_id)
|
|
db.add(ocr)
|
|
db.commit()
|
|
db.refresh(ocr)
|
|
return ocr
|
|
|
|
@router.get("/")
|
|
def list_ocr(db: Session = Depends(get_db)):
|
|
return db.query(OCRResult).all()
|