Format everything
This commit is contained in:
@@ -11,14 +11,18 @@ from ..dtos.houses_list_response import HousesListResponse, HouseResponse
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
|
||||
@router.post("")
|
||||
async def create_house(body: HouseCreateRequest, auth: Annotated[AuthContext, Depends()], house_repository: Annotated[HouseRepository, Depends()], owner_repository: Annotated[OwnerRepository, Depends()]) -> HouseCreateResponse:
|
||||
async def create_house(
|
||||
body: HouseCreateRequest,
|
||||
auth: Annotated[AuthContext, Depends()],
|
||||
house_repository: Annotated[HouseRepository, Depends()],
|
||||
owner_repository: Annotated[OwnerRepository, Depends()],
|
||||
) -> HouseCreateResponse:
|
||||
owner = await owner_repository.get_by_id(auth.user.id)
|
||||
|
||||
|
||||
if not owner:
|
||||
new_owner = Owner(
|
||||
user_id=auth.user.id
|
||||
)
|
||||
new_owner = Owner(user_id=auth.user.id)
|
||||
|
||||
await owner_repository.save(new_owner)
|
||||
|
||||
@@ -28,24 +32,33 @@ async def create_house(body: HouseCreateRequest, auth: Annotated[AuthContext, De
|
||||
city=body.city,
|
||||
country=body.country,
|
||||
price=body.price,
|
||||
description=body.description
|
||||
description=body.description,
|
||||
)
|
||||
|
||||
await house_repository.save(house)
|
||||
|
||||
return HouseCreateResponse(
|
||||
id=str(house.id)
|
||||
)
|
||||
|
||||
return HouseCreateResponse(id=str(house.id))
|
||||
|
||||
|
||||
@router.get("")
|
||||
async def get_all_houses(house_repository: Annotated[HouseRepository, Depends()], limit: int = 100, offset: int = 0) -> HousesListResponse:
|
||||
async def get_all_houses(
|
||||
house_repository: Annotated[HouseRepository, Depends()],
|
||||
limit: int = 100,
|
||||
offset: int = 0,
|
||||
) -> HousesListResponse:
|
||||
all_houses = await house_repository.get_all(offset=offset, limit=limit)
|
||||
|
||||
house_responses = ([HouseResponse(id=str(house.id), description=house.description, address=house.address, city=house.city, country=house.country, price=house.price) for house in all_houses])
|
||||
|
||||
house_responses = [
|
||||
HouseResponse(
|
||||
id=str(house.id),
|
||||
description=house.description,
|
||||
address=house.address,
|
||||
city=house.city,
|
||||
country=house.country,
|
||||
price=house.price,
|
||||
)
|
||||
for house in all_houses
|
||||
]
|
||||
print(house_responses)
|
||||
|
||||
return HousesListResponse(
|
||||
houses=house_responses
|
||||
)
|
||||
|
||||
return HousesListResponse(houses=house_responses)
|
||||
|
||||
@@ -10,22 +10,27 @@ router = APIRouter()
|
||||
|
||||
|
||||
@router.get("")
|
||||
async def get_owners(owner_repository: Annotated[OwnerRepository, Depends()]) -> OwnerListResponse:
|
||||
async def get_owners(
|
||||
owner_repository: Annotated[OwnerRepository, Depends()],
|
||||
) -> OwnerListResponse:
|
||||
owners = await owner_repository.get_all()
|
||||
|
||||
owners_response = [OwnerResponse(id=str(owner.id), user_id=str(owner.user_id)) for owner in owners]
|
||||
owners_response = [
|
||||
OwnerResponse(id=str(owner.id), user_id=str(owner.user_id)) for owner in owners
|
||||
]
|
||||
|
||||
return OwnerListResponse(owners=owners_response)
|
||||
|
||||
return OwnerListResponse(
|
||||
owners=owners_response
|
||||
)
|
||||
|
||||
@router.get("/{id}")
|
||||
async def get_owner(id: str, owner_repository: Annotated[OwnerRepository, Depends()], user_repository: Annotated[UserRepository, Depends()]) -> OwnerDetailResponse:
|
||||
async def get_owner(
|
||||
id: str,
|
||||
owner_repository: Annotated[OwnerRepository, Depends()],
|
||||
user_repository: Annotated[UserRepository, Depends()],
|
||||
) -> OwnerDetailResponse:
|
||||
owner = await owner_repository.get_by_id(id)
|
||||
user = await user_repository.get_by_id(owner.user_id)
|
||||
|
||||
return OwnerDetailResponse(
|
||||
id=str(owner.id),
|
||||
user_id=str(owner.user_id),
|
||||
email=user.email
|
||||
)
|
||||
id=str(owner.id), user_id=str(owner.user_id), email=user.email
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user