Add sorting

This commit is contained in:
Jacob Windsor
2025-02-19 17:52:11 +01:00
parent dc0d2acf53
commit 6b458654a7
2 changed files with 21 additions and 7 deletions
+6 -3
View File
@@ -1,4 +1,4 @@
from typing import Annotated
from typing import Annotated, Literal
from fastapi import APIRouter, Depends
@@ -48,10 +48,14 @@ async def create_house(
@router.get("")
async def get_all_houses(
house_repository: Annotated[HouseRepository, Depends()],
order_by: Literal["PRICE"] = "PRICE",
sort_order: Literal["ASC", "DESC"] = "DESC",
limit: int = 100,
offset: int = 0,
) -> HousesListResponse:
all_houses = await house_repository.get_all(offset=offset, limit=limit)
all_houses = await house_repository.get_all(
offset=offset, limit=limit, order_by=order_by, sort_order=sort_order
)
house_responses = [
HouseResponse(
@@ -64,6 +68,5 @@ async def get_all_houses(
)
for house in all_houses
]
print(house_responses)
return HousesListResponse(houses=house_responses)