예제 #1
0
def getLandownerLand(db, req_data):
    '''Return the land owned by the user if a landowner'''
    sessionID = req_data['sessionID']
    returnObj = []
    
    userObj = data.getTableEntry(db, data.COLLECTION_USERS, {"sessionID": sessionID})
    if(userObj == []):
        return {"Status": "Failure: Invalid sessionID"}
    # user is valid 

    landownerObject = data.getTableEntry(db, data.COLLECTION_LANDOWNERS, {"uname": userObj[0]['uname']})
    
    if(landownerObject == []):
        return {"Status": "Failure: Invalid landowner"}
    # landowner is valid 
    
    landObjs = data.getAllFromTable(db, data.COLLECTION_LAND)
    
    if(landObjs == []):
        return {"Status": "Failure: Missing land objects"}
        
    for land in landObjs:
        if(land['landID'] in landownerObject[0]['landIDs']):
            land.pop('amenities')
            returnObj.append(land)
            
    return returnObj
예제 #2
0
def getLandownerContact(db, req_data):
    sessionID = req_data['sessionID']
    landID = req_data['landID']
    
    ### verification
    # verify user exists
    userObject = data.getTableEntry(db, data.COLLECTION_USERS, {"sessionID": sessionID})
    if(userObject == []):
        return {"Status": "Failure: Invalid sessionID"} 
    # verify they are a tenant
    if(userObject[0]['role'] != 'tenant'):
        return {"Status": "Failure: Invalid user type"} 
    
    # get all landowners
    
    landowners = data.getAllFromTable(db, data.COLLECTION_LANDOWNERS)
    
    if(landowners == []):
        return {"Status": "Failure"}
    
    for entry in landowners:
        if(landID in entry["landIDs"]):
            # get contact from uname of landowner
            uname = entry['uname']
            returnObj = data.getTableEntry(db, data.COLLECTION_USERS, {"uname": uname})
            return {"phone": returnObj[0]['phoneNo'], "email": returnObj[0]['email']}
        
    return {"Status": "Failure"}
예제 #3
0
def getInterestedBuyers(db, sessionID):
    '''Gets the buyer objects that are buying what the tenant plots are producing'''
    buyerList = []
    # get user from sessionID
    userObject = data.getSession(db, sessionID)
    if(userObject == []):
        return None
    
    # get username from sessionID into variable
    uname = userObject[0]['uname']
    # get tenant object from username
    tenantObject = data.getTableEntry(db, data.COLLECTION_TENANTS, {"uname": uname})
    # if the user is a tenant
    if(tenantObject == []):
        return None
    
    # get the specific produce of the tenant
    sellingObject = tenantObject[0]['produce']
    if(sellingObject == []):
        return None
    
    # get all buyers
    buyersObject = data.getAllFromTable(db, data.COLLECTION_BUYERS)
    if(buyersObject == []):
        return None
    
    # for every buyer, compare buying product with tenants sold items
    for buyer in buyersObject:
        produceList = []
        for produce in sellingObject:
            if produce[0] in buyer['buying']:
                produceList.append(produce[0])
        if(produceList != []):
            buyerList.append([buyer['uname'], produceList])
    return buyerList
예제 #4
0
def getPlotDetails(db, req_data):
    '''Returns a detailed object of land and plot information as well as tenant information if rented'''
    sessionID = req_data['sessionID']
    landID = req_data['landID']
    plotID = req_data['plotID']
    
    returnObject = {}
    
    userObject = data.getTableEntry(db, data.COLLECTION_USERS, {"sessionID": sessionID})
    if(userObject == []):
        return {"Status": "Failure: Invalid sessionID"}
    
    landownerObject = data.getTableEntry(db, data.COLLECTION_LANDOWNERS, {"uname": userObject[0]['uname']})
    if(landownerObject == []):
        return {"Status": "Failure: Invalid account type"}
    
    landObject = data.getTableEntry(db, data.COLLECTION_LAND, {"landID": landID})
    if(landObject == []):
        return {"Status": "Failure: Invalid landID"}
    
    plotData = data.getTableEntry(db, data.COLLECTION_PLOTS, {"landID": landID, "plotID": plotID})
    if(landObject == []):
        return {"Status": "Failure: Invalid plot data"}
    
    allTenants = data.getAllFromTable(db, data.COLLECTION_TENANTS) # NEEDS WORKING AROUND, THIS WILL BE SLOWER OVER TIME
    
    rentedBy = ""

    for entry in allTenants:
        for plots in entry['plots']:
            if(landID in plots and plotID in plots):
                rentedBy = entry['uname']
                
                
    rentedUserObject = data.getTableEntry(db, data.COLLECTION_USERS, {"uname": rentedBy})
    if(rentedUserObject != []):
        # not rented by anyone
        returnObject.update({"tenantData": {"fName": rentedUserObject[0]['fName'],"lName": rentedUserObject[0]['lName'], "email": rentedUserObject[0]['email'],"phoneNo": rentedUserObject[0]['phoneNo']}})
    else:
        print("Not rented by anyone")
        returnObject.update({"tenantData":""})
    
    returnObject.update({"plotData": {"plotID": plotData[0]['plotID'],"price": plotData[0]['price'], "waitingList": plotData[0]['waitingList'], "coords": plotData[0]['coords']}})
    
    returnObject.update({"landData": {"amenities": landObject[0]['amenities']}})
    
    return returnObject
예제 #5
0
def getLandEntries(db, req_data):
    '''Given a sessionID, all land entries in land table (for browsing plots)'''
    sessionID = req_data['sessionID']
    
    userObj = data.getTableEntry(db, data.COLLECTION_USERS, {"sessionID": sessionID})
    if(userObj == []):
        return {"Status": "Failure: Invalid sessionID"}
    # user is valid 
    # ignore user object now, get all land entries
    landObjs = data.getAllFromTable(db, data.COLLECTION_LAND)
    
    if(landObjs == []):
        return {"Status": "Failure: Missing land objects"}
        
    for land in landObjs:
        land.pop('amenities')
    return landObjs
예제 #6
0
def getLandEntriesOp(db, req_data):
    '''Given a sessionID, all land entries in land table (for browsing plots) and their associated plot information'''
    sessionID = req_data['sessionID']
    returnObject = []
    
    userObj = data.getTableEntry(db, data.COLLECTION_USERS, {"sessionID": sessionID})
    if(userObj == []):
        return {"Status": "Failure: Invalid sessionID"}
    # user is valid 
    # ignore user object now, get all land entries
    landObjs = data.getAllFromTable(db, data.COLLECTION_LAND)
    
    if(landObjs == []):
        return {"Status": "Failure: Missing land objects"}
        
    for land in landObjs:
        returnObject.append(browsePlots(db, {"sessionID": sessionID, "landID": land["landID"]})[0])
        
    return returnObject
예제 #7
0
def getInterestedSuppliers(db, req_data):
    '''Gets supplier entries'''
    sessionID = req_data['sessionID']
        
    userObject = data.getTableEntry(db, data.COLLECTION_USERS, {"sessionID": sessionID})
    if(userObject == []):
        return {"Status": "Failure: Invalid sessionID"}
    # user is valid 
    
    if(userObject[0]['role'] != "landowner"):
        return {"Status": "Failure: Not a landowner"}
    
    
    suppliersObject = data.getAllFromTable(db, data.COLLECTION_SUPPLIERS)
    
    # update buying items entry with new array from req_data
    
    toReturn = []
    
    for item in suppliersObject:
        toReturn.append(item)
        
    return toReturn