def create_ride(): #r = requests.post('http://18.233.82.73:80/api/v1/db/write', json={'table_name':'dummyt','db_action':'add','db_data':"dummy"}) #Getting request body req=request.get_json() #Getting enum from constants file allplaces = placeList() avail = 0 #Validating source and destination if int(req["source"]) in allplaces and int(req["destination"]) in allplaces: avail =1 #Sending request to read, checking if user who is creating ride exists cheader = {"Origin":"34.201.40.30"} to_chk = requests.get('http://RideShare-1269314373.us-east-1.elb.amazonaws.com/api/v1/users',headers=cheader) #somelist = to_chk.text.strip('"][').split(', ') #somelist = json.loads(to_chk.text) if(to_chk.status_code!=204): somelist = json.loads(to_chk.text) else: return "User doesn't exist",400 if((req["created_by"] in somelist) and avail == 1): #Sending request to write, adding new ride to Rides table r = requests.post('http://18.233.82.73:80/api/v1/db/write', json={'table_name':'Rides','db_action':'add','db_data':req}) return {},201 else: return "Invalid user/source or destination",400
def list_rides(): #r = requests.post('http://127.0.0.1:5000/api/v1/db/write', json={'table_name':'dummyt','db_action':'add','db_data':"dummy"}) #Getting enum from constants file allplaces = placeList() #extracting source and destination from url src = request.args.get("source") dst = request.args.get("destination") avail=0 #Validating source and destination if int(src) in allplaces and int(dst) in allplaces: avail =1 if avail==0: return "Invalid source/destination",400 #obtaining current date-time current = datetime.now() cur_str = current.strftime("%d-%m-%Y:%S-%M-%H") cur_dt = datetime.strptime(cur_str,"%d-%m-%Y:%S-%M-%H") #JSON of required data req = { "src" : int(src), "dst" : int(dst), "dtime" : cur_str } #Sending request to read, obtaining details of upcoming rides to_chk = requests.post("http://127.0.0.1:5000/api/v1/db/read",json={'table_name':'Rides','db_action':'get','db_data':req}) if(to_chk.text=='[]'): return {},200 print(to_chk.text) return to_chk.text,200
def create_ride(): #Getting request body req = request.get_json() #Getting enum from constants file allplaces = placeList() avail = 0 #Validating source and destination if int(req["source"]) in allplaces and int( req["destination"]) in allplaces: avail = 1 #Sending request to read, checking if user who is creating ride exists to_chk = requests.get('http://users:5000/api/v1/users') #somelist = to_chk.text.strip('"][').split(', ') somelist = json.loads(to_chk.text) if ((req["created_by"] in somelist) and avail == 1): #Sending request to write, adding new ride to Rides table r = requests.post('http://127.0.0.1:5000/api/v1/db/write', json={ 'table_name': 'Rides', 'db_action': 'add', 'db_data': req }) return {}, 201 else: return "Invalid user/source or destination", 400