
- Fixed Pydantic configuration using ConfigDict for latest Pydantic version - Fixed import order in alembic/env.py for proper module imports - Applied code formatting with Ruff - Optimized database connection settings - Ensured proper error handling for API endpoints generated with BackendIM... (backend.im)
33 lines
881 B
Python
33 lines
881 B
Python
from sqlalchemy.orm import Session
|
|
from app.models.calculation import Calculation
|
|
from app.schemas.calculation import CalculationCreate
|
|
|
|
|
|
def create_calculation(
|
|
db: Session, calc: CalculationCreate, result: float
|
|
) -> Calculation:
|
|
db_calculation = Calculation(
|
|
operation=calc.operation,
|
|
first_number=calc.first_number,
|
|
second_number=calc.second_number,
|
|
result=result,
|
|
)
|
|
db.add(db_calculation)
|
|
db.commit()
|
|
db.refresh(db_calculation)
|
|
return db_calculation
|
|
|
|
|
|
def get_calculations(db: Session, skip: int = 0, limit: int = 100):
|
|
return (
|
|
db.query(Calculation)
|
|
.order_by(Calculation.created_at.desc())
|
|
.offset(skip)
|
|
.limit(limit)
|
|
.all()
|
|
)
|
|
|
|
|
|
def get_calculation(db: Session, calculation_id: int):
|
|
return db.query(Calculation).filter(Calculation.id == calculation_id).first()
|