def get_tenant_house(self, tenantEmail): tenantSnapshot = self._db.collection("Tenant").document( tenantEmail).get() reference = tenantSnapshot.get("houseReference") print(reference) houseSnapshot = self._db.document(reference.path).get() house = House(houseSnapshot.get("address"), houseSnapshot.get("rent"), houseSnapshot.get("size"), houseSnapshot.get("bedNumber"), houseSnapshot.get("bathNumber"), houseSnapshot.get("landlordEmail"), houseSnapshot.get("url"), houseSnapshot.get("description"), houseSnapshot.get("isPosted"), houseSnapshot.get("amenities"), houseSnapshot.get("utilities")) for profileReference in houseSnapshot.get("profiles"): profile = self._db.document(profileReference.path).get() p = Profile(profile.get("firstName"), profile.get("lastName"), profile.get("email"), profile.get("bio")) house.add_leaf(p) try: for tenantReference in houseSnapshot.get("tenants"): tenant = self._db.document(tenantReference.path).get() t = Tenant(tenant.get("firstName"), tenant.get("lastName"), tenant.get("password"), tenant.get("password2"), tenant.get("tenantEmail"), tenant.get("landlordEmail"), tenant.get("tenantRating")) house.add_leaf(t) except KeyError: print("Error: Tenant key error") return house.get_dictionary()
def get_landlord_houses(self, email): landlordHouses = [] landlordSnapshot = self._db.collection("Landlord").document( email).get() if not landlordSnapshot.exists: return {"Result": "Error: Landlord does not exist"} try: for reference in landlordSnapshot.get("houses"): houseReference = self._db.document(reference.path).get() house = House(houseReference.get("address"), houseReference.get("rent"), houseReference.get("size"), houseReference.get("bedNumber"), houseReference.get("bathNumber"), houseReference.get("landlordEmail"), houseReference.get("url"), houseReference.get("description"), houseReference.get("isPosted"), houseReference.get("amenities"), houseReference.get("utilities")) try: for profileReference in houseReference.get("profiles"): profile = self._db.document( profileReference.path).get() p = Profile(profile.get("firstName"), profile.get("lastName"), profile.get("email"), profile.get("bio")) house.add_leaf(p) except KeyError: pass try: for tenantReference in houseReference.get("tenants"): tenant = self._db.document(tenantReference.path).get() t = Tenant(tenant.get("firstName"), tenant.get("lastName"), tenant.get("password"), tenant.get("password2"), tenant.get("tenantEmail"), tenant.get("landlordEmail"), tenant.get("tenantRating")) house.add_leaf(t) except KeyError: pass landlordHouses.append(house.get_dictionary()) except KeyError: return {"Result": "No houses found"} return landlordHouses
def search_houses(self, province, city, price, amenities): filteredHouses = [] houseCollection = self._db.collection("House").get() for houseDocument in houseCollection: if houseDocument.get("isPosted") == True: if houseDocument.get("province") == province: if houseDocument.get("city") == city: if houseDocument.get("rent") <= price: if houseDocument.get("amenities") == amenities: house = House( houseDocument.get("address"), houseDocument.get("rent"), houseDocument.get("size"), houseDocument.get("bedNumber"), houseDocument.get("bathNumber"), houseDocument.get("landlordEmail"), houseDocument.get("url"), houseDocument.get("description"), houseDocument.get("isPosted"), houseDocument.get("amenities"), houseDocument.get("utilities")) try: for profileReference in houseDocument.get( "profiles"): profile = self._db.document( profileReference.path).get() p = Profile(profile.get("firstName"), profile.get("lastName"), profile.get("email"), profile.get("bio")) house.add_leaf(p) except KeyError: pass try: for tenantReference in houseDocument.get( "tenants"): tenant = self._db.document( tenantReference.path).get() t = Tenant(tenant.get("firstName"), tenant.get("lastName"), tenant.get("password"), tenant.get("password2"), tenant.get("tenantEmail"), tenant.get("landlordEmail"), tenant.get("tenantRating")) house.add_leaf(t) except KeyError: pass filteredHouses.append(house.get_dictionary()) return filteredHouses
def add_house(self, houseRequest): if (self._db.collection("House").document( houseRequest["address"]).get().exists): return {"Result": "Error: House already exists"} houseRef = self._db.collection("House").document( houseRequest["address"]) landlordRef = self._db.collection("Landlord").document( houseRequest["landlordEmail"]) location = Location() locationData = location.get_location_from_address( houseRequest["address"]) house = House(houseRequest["address"], houseRequest["rent"], houseRequest["size"], houseRequest["bedNumber"], houseRequest["bathNumber"], houseRequest["landlordEmail"], locationData["url"], houseRequest["description"], False, houseRequest["amenities"], houseRequest["utilities"]) houseRef.set(house.get_dictionary()) houseRef.update({ "province": locationData["province"], "city": locationData["city"] }) houses = [] landlordSnapshot = landlordRef.get() try: houseReferences = landlordSnapshot.get("houses") for reference in houseReferences: houses.append(reference) houses.append(houseRef.get().reference) landlordRef.update({"houses": houses}) except KeyError: houses.append(houseRef.get().reference) landlordRef.update({"houses": houses}) return {"Result": "House added successfully"}