Exemple #1
0
    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()
Exemple #2
0
    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
Exemple #3
0
    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