[product] filtering reverted for now
This commit is contained in:
parent
43049dcf2b
commit
50b49c8bb7
2 changed files with 0 additions and 52 deletions
|
@ -39,35 +39,6 @@ class Product(Base, CommonMixin):
|
||||||
async for row in stream:
|
async for row in stream:
|
||||||
yield row
|
yield row
|
||||||
|
|
||||||
@classmethod
|
|
||||||
async def list_all_for_user(
|
|
||||||
cls,
|
|
||||||
session: AsyncSession,
|
|
||||||
offset: int,
|
|
||||||
limit: int,
|
|
||||||
user: User,
|
|
||||||
q: Optional[str] = None,
|
|
||||||
) -> AsyncIterator["Product"]:
|
|
||||||
from .meal import Meal
|
|
||||||
from .diary import Diary
|
|
||||||
from .entry import Entry
|
|
||||||
|
|
||||||
query = (
|
|
||||||
select(cls)
|
|
||||||
.join(Entry, isouter=True)
|
|
||||||
.join(Meal, isouter=True)
|
|
||||||
.join(Diary, isouter=True)
|
|
||||||
.where(Diary.user_id == user.id)
|
|
||||||
)
|
|
||||||
|
|
||||||
if q:
|
|
||||||
query = query.filter(cls.name.ilike(f"%{q.lower()}%"))
|
|
||||||
|
|
||||||
query = query.order_by(Entry.last_changed.desc()).offset(offset).limit(limit)
|
|
||||||
stream = await session.stream_scalars(query.order_by(cls.id))
|
|
||||||
async for row in stream:
|
|
||||||
yield row
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
async def create(
|
async def create(
|
||||||
cls,
|
cls,
|
||||||
|
|
|
@ -20,26 +20,3 @@ def test_list_product(client):
|
||||||
for product in data:
|
for product in data:
|
||||||
assert product["id"] not in product_ids
|
assert product["id"] not in product_ids
|
||||||
product_ids.add(product["id"])
|
product_ids.add(product["id"])
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.dependency(depends=["test_list_product"])
|
|
||||||
def test_products_list_by_latest_usage(
|
|
||||||
client, product_payload_factory, entry_payload_factory
|
|
||||||
):
|
|
||||||
today = datetime.date.today().isoformat()
|
|
||||||
response = client.get("diary", params={"date": today})
|
|
||||||
assert response.status_code == 200, response.json()
|
|
||||||
|
|
||||||
meal_id = response.json()["meals"][0]["id"]
|
|
||||||
|
|
||||||
response = client.get("product")
|
|
||||||
product_id = response.json()["products"][0]["id"]
|
|
||||||
|
|
||||||
entry_payload = entry_payload_factory(meal_id, product_id, 100.0)
|
|
||||||
response = client.post("entry", json=entry_payload)
|
|
||||||
|
|
||||||
for _ in range(5):
|
|
||||||
client.post("product", json=product_payload_factory()).json()["id"]
|
|
||||||
|
|
||||||
response = client.get("product")
|
|
||||||
assert response.json()["products"][0]["id"] == product_id
|
|
||||||
|
|
Loading…
Reference in a new issue