def getbillid(bill_id): start = time.time() username = request.authorization.username passwordinfo = request.authorization.password bill_sc = Billschema(many=False) data1 = request.get_json() dbtime = time.time() flag = checkauthentication(username, passwordinfo) dur = (time.time() - dbtime) * 1000 c.timing("dbconnect", dur) if flag == True: result = Credential.select_user_by_email(username) user_sc = Credentialschema() data = user_sc.dump(result) owner_id = data.get('id') dbtime = time.time() result2 = Bills.select_user_by_billid(bill_id) dur = (time.time() - dbtime) * 1000 c.timing("dbconnect", dur) bill_sc = Billschema(many=False) data2 = bill_sc.dump((result2)) owner_id2 = data2.get('owner_id') if owner_id == owner_id2: json_data = request.get_json() list_var = json_data["categories"] list_var = str(list_var) list_var = ((list_var.strip("[")).strip("]")).strip("'") json_data["categories"] = list_var vendor_name = json_data.get('vendor') bill_date = json_data.get('bill_date') due_date = json_data.get('due_date') amount_due = json_data.get('amount_due') categories = json_data.get('categories') payment_status = json_data.get('paymentStatus') price = json_data.get('amount_due') if price < 0.1 or price is None: return custom_http_code("amount bad request", 400) if payment_status != "paid" or payment_status != "due" or payment_status != "no_payment" or payment_status != "no_payment_required": payment_status = "due" dbtime = time.time() state = Bills.query.filter_by(id=bill_id).update( dict(vendor=vendor_name, bill_date=bill_date, due_date=due_date, amount_due=amount_due, categories=categories, paymentStatus=payment_status)) db.session.commit() dur = (time.time() - dbtime) * 1000 c.timing("dbconnect", dur) bill_schema = Billschema(many=False) data = Bills.select_user_by_billid(bill_id) query_result = bill_schema.dump(data) #check attachment dbtime = time.time() result = File.select_file_by_billid(bill_id) dur = (time.time() - dbtime) * 1000 c.timing("dbconnect", dur) if not result: attachmentfile = {} query_result["attachments"] = attachmentfile return jsonify(query_result) #if attachment print(result) #attachmentb results dump file_sc = File_schema_output(many=False) data = file_sc.dumps(result) #bill info dict attachmentfile = query_result #attachment dict final = json.loads(data) #add two dict attachmentfile["attachments"] = final c.incr("putbillcount") dur = (time.time() - start) * 1000 c.timing("putbillcount", dur) return jsonify(attachmentfile) else: c.incr("putbillcount") dur = (time.time() - start) * 1000 c.timing("putbillcount", dur) return custom_http_code('Unauthorised', 401) else: return custom_http_code('invalid login', 401)
def getasinglebill(billid): start = time.time() # print(billid) username = request.authorization.username passwordinfo = request.authorization.password # bill_sc = Billschema(many=False) # data = request.get_json() dbtime = time.time() flag = checkauthentication(username, passwordinfo) dur = (time.time() - dbtime) * 1000 c.timing("dbconnect", dur) print(billid) if flag == True: print(billid) dbtime = time.time() result = Credential.select_user_by_email(username) dur = (time.time() - dbtime) * 1000 c.timing("dbconnect", dur) user_sc = Credentialschema() data = user_sc.dump(result) owner_id = data.get('id') print(owner_id) dbtime = time.time() result2 = Bills.select_user_by_billid(billid) dur = (time.time() - dbtime) * 1000 c.timing("dbconnect", dur) bill_sc = Billschema(many=False) data2 = bill_sc.dump((result2)) owner_id_test = data2.get('owner_id') print(owner_id_test) #return "before delete" if owner_id == owner_id_test: bill_schema = Billschema(many=False) dbtime = time.time() data = Bills.select_user_by_billid(billid) dur = (time.time() - dbtime) * 1000 c.timing("dbconnect", dur) query_result = bill_schema.dumps(data) query_result = json.loads(query_result) #check attachment dbtime = time.time() result = File.select_file_by_billid(billid) dur = (time.time() - dbtime) * 1000 c.timing("dbconnect", dur) if not result: attachmentfile = {} query_result["attachments"] = attachmentfile return jsonify(query_result) #if attachment print(result) #attachmentb results dump file_sc = File_schema_output(many=False) data = file_sc.dumps(result) #bill info dict attachmentfile = query_result #attachment dict final = json.loads(data) #add two dict attachmentfile["attachments"] = final c.incr("getbillcount") dur = (time.time() - start) * 1000 c.timing("getbillcount", dur) return jsonify(attachmentfile) else: c.incr("getbillcount") dur = (time.time() - start) * 1000 c.timing("getbillcount", dur) return custom_http_code("invalid bill id", 404) else: return custom_http_code("unzauthorized", 401)