first commit
This commit is contained in:
23
routes/info/pricing.py
Normal file
23
routes/info/pricing.py
Normal file
@@ -0,0 +1,23 @@
|
||||
from fastapi import APIRouter, Depends
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
from sqlalchemy import select
|
||||
from database import get_db
|
||||
from models import Pricing_Oil_Oil
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
@router.get("/current")
|
||||
async def get_current_pricing(db: AsyncSession = Depends(get_db)):
|
||||
# Get the latest pricing record
|
||||
pricing = await db.execute(
|
||||
select(Pricing_Oil_Oil).order_by(Pricing_Oil_Oil.id.desc()).limit(1)
|
||||
)
|
||||
pricing = pricing.scalar_one_or_none()
|
||||
|
||||
if not pricing:
|
||||
return {"price_per_gallon": 0.00, "message": "No pricing available"}
|
||||
|
||||
return {
|
||||
"price_per_gallon": float(pricing.price_for_customer),
|
||||
"date": pricing.date.isoformat() if pricing.date else None
|
||||
}
|
||||
Reference in New Issue
Block a user