This commit is contained in:
Tiago vasconcelos 2022-09-15 15:52:08 +01:00
parent ad98cb0d45
commit ee47575431
3 changed files with 15 additions and 10 deletions

View file

@ -201,12 +201,15 @@ async def get_diagonalley_stalls(wallet_ids: Union[str, List[str]]) -> List[Stal
)
return [Stalls(**row) for row in rows]
async def get_diagonalley_stalls_by_ids(stall_ids: Union[str, List[str]]) -> List[Stalls]:
async def get_diagonalley_stalls_by_ids(
stall_ids: Union[str, List[str]]
) -> List[Stalls]:
q = ",".join(["?"] * len(stall_ids))
rows = await db.fetchall(
f"SELECT * FROM diagonalley.stalls WHERE id IN ({q})", (*stall_ids,)
)
return [Stalls(**row) for row in rows]
return [Stalls(**row) for row in rows]
async def delete_diagonalley_stall(stall_id: str) -> None:
@ -353,10 +356,10 @@ async def get_diagonalley_market(market_id: str) -> Optional[Market]:
async def get_diagonalley_market_stalls(market_id: str):
rows = await db.fetchall(
"SELECT * FROM diagonalley.market_stalls WHERE marketid = ?", (market_id,)
)
)
ids = [row["stallid"] for row in rows]
ids = [row["stallid"] for row in rows]
return await get_diagonalley_stalls_by_ids(ids)

View file

@ -64,15 +64,17 @@ async def display(request: Request, stall_id):
@diagonalley_ext.get("/market/{market_id}", response_class=HTMLResponse)
async def display(request: Request, market_id):
market = await get_diagonalley_market(market_id)
if not market:
raise HTTPException(
status_code=HTTPStatus.NOT_FOUND, detail="Marketplace doesn't exist."
)
stalls = await get_diagonalley_market_stalls(market_id)
stalls_ids = [stall.id for stall in stalls]
products = [product.dict() for product in await get_diagonalley_products(stalls_ids)]
products = [
product.dict() for product in await get_diagonalley_products(stalls_ids)
]
return diagonalley_renderer().TemplateResponse(
"diagonalley/market.html",
@ -80,6 +82,6 @@ async def display(request: Request, market_id):
"request": request,
"market": market,
"stalls": [stall.dict() for stall in stalls],
"products": products
"products": products,
},
)

View file

@ -444,7 +444,7 @@ async def api_diagonalley_markets(wallet: WalletTypeInfo = Depends(get_key_type)
async def api_diagonalley_market_stalls(market_id: str):
stall_ids = await get_diagonalley_market_stalls(market_id)
return stall_ids
@diagonalley_ext.post("/api/v1/markets")
@diagonalley_ext.put("/api/v1/markets/{market_id}")