Queue gallery enrichment jobs
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
from fastapi import APIRouter, Depends, HTTPException, Query
|
||||
from sqlalchemy import func, select
|
||||
from sqlalchemy.orm import selectinload
|
||||
|
||||
from ..deps import get_persistence
|
||||
from ...storage.db import PersistenceService
|
||||
@@ -24,7 +25,7 @@ def list_cars(
|
||||
):
|
||||
# Список авто с фильтрами.
|
||||
with persistence.session_scope() as session:
|
||||
query = select(Car)
|
||||
query = select(Car).options(selectinload(Car.images))
|
||||
|
||||
if brand:
|
||||
query = query.where(Car.brand.ilike(f"%{brand}%"))
|
||||
@@ -61,7 +62,9 @@ def get_car(
|
||||
):
|
||||
# Карточка авто с фото.
|
||||
with persistence.session_scope() as session:
|
||||
car = session.get(Car, car_id)
|
||||
car = session.execute(
|
||||
select(Car).options(selectinload(Car.images)).where(Car.id == car_id)
|
||||
).scalar_one_or_none()
|
||||
if car is None:
|
||||
raise HTTPException(status_code=404, detail="Car not found")
|
||||
return CarRead.model_validate(car).model_dump(mode="json")
|
||||
@@ -75,7 +78,7 @@ def get_car_by_origin(
|
||||
# Поиск по origin_id.
|
||||
with persistence.session_scope() as session:
|
||||
car = session.execute(
|
||||
select(Car).where(Car.origin_id == origin_id)
|
||||
select(Car).options(selectinload(Car.images)).where(Car.origin_id == origin_id)
|
||||
).scalars().first()
|
||||
if car is None:
|
||||
raise HTTPException(status_code=404, detail="Car not found")
|
||||
|
||||
Reference in New Issue
Block a user