def search_item(loc): try: testdb = db() resultlist = testdb.search_item_by_loc(loc) json_string = json.dumps([ob.__dict__ for ob in resultlist]) return json_string except Exception as e: print(e)
def create(): try: testdb = db() name = request.json['name'] loc = request.json['location'] desc = request.json['description'] items = item() items.newItem(name, loc, desc) testdb.insert_item_db(items) resp = jsonify({"Action": 'Item Added Successfully'}) resp.status_code = 200 return resp except Exception as e: print(e)
def delete_item(item_id): try: testdb = db() result = testdb.delete_item(item_id) if result: resp = jsonify( {"Action": 'Item Deleted Successfully {}'.format(item_id)}) resp.status_code = 200 return resp else: resp = jsonify( {"Action": 'Item Not Found with id {}'.format(item_id)}) resp.status_code = 200 return resp except Exception as e: print(e)
def login_user(): try: testdb = db() email = request.json['email'] password = request.json['password'] if testdb.login_user(email, password): resp = jsonify({"Action": 'User Logged In Successfully'}) resp.status_code = 200 return resp else: resp = jsonify({ "Action": 'User Login Failure', "reason": "Email or Password Incorrect" }) resp.status_code = 200 return resp except Exception as e: print(e)
def register_user(): try: testdb = db() username = request.json['username'] email = request.json['email'] password = request.json['password'] user = User() user.User(username, email, password) excep = testdb.register_user(user) if excep: resp = jsonify({"Action": 'Error occured {}'.format(excep)}) resp.status_code = 200 return resp else: resp = jsonify({"Action": 'User Registered Successfully'}) resp.status_code = 200 return resp except Exception as e: print(e)
def update(): try: testdb = db() item_id = request.json['item_id'] name = request.json['name'] loc = request.json['location'] desc = request.json['description'] items = item() items.newItem(name, loc, desc) result = testdb.update_item(items, item_id) if result: resp = jsonify({"Action": 'Item Updated Successfully'}) resp.status_code = 200 return resp else: resp = jsonify({ "Action": 'Item with Item Id {} is not found'.format(item_id) }) resp.status_code = 200 return resp except Exception as e: print(e)
def view(): testdb = db() resultlist = testdb.view_items() json_string = json.dumps([ob.__dict__ for ob in resultlist]) return json_string
# -*- coding: utf-8 -*- """ Created on Thu Oct 31 16:38:39 2019 @author: Hawkeye """ from DBhandler import DatabaseHandler as db from User import User from Items import Item as item import time time.sleep(5) testdb = db() # user = User() # user.username="******" # user.email="*****@*****.**" # user.password="******" # items = item() # name = 'name' # loc = 'location' # desc = 'description' testdb.delete_item(1) # items.newItem(name,loc,desc) # testdb.insert_item_db(items)