def buy_item(args): DB.buy_item(args) response = jsonify({ "message": "Congratulations {user}! {item} buyed successfully".format( user=args["user_name"], item=args["name"]) }) response.status_code = 201 return response
def register_user(args): try: DB.register_user(args) response = jsonify({ "message": "User {} added successfully".format(args["user_name"]) }) response.status_code = 201 except errors.NotUniqueError: response = jsonify({ "message": "The user {} already exists".format(args["user_name"]) }) response.status_code = 409 finally: return response
def get_inventory(): items = DB.get_inventory() if not items: response = jsonify({"message": "The inventory is empty"}) response.status_code = 404 return response else: return items
def get_users(): users = DB.get_users() if not users: response = jsonify({"message": "There are no users :("}) response.status_code = 404 return response else: return users
def get_objeto(name): if not name: abort(404, message="Es necesario el nombre del item") item = DB.get_objeto(name) if not item: abort(404, message="El item {} no existe".format(name)) return item
def get_item(name): if not name: abort(404, message="Es necesario el nombre del item") item = DB.get_item(name) if not item: abort(404, message="El item {} no existe".format(name)) return { 'name': item[0], 'sell_in': item[1], 'quality': item[2] }
def get_personal_inventory(args): personal_inventory = DB.get_personal_inventory(args) if personal_inventory: return personal_inventory else: response = jsonify({ "message": "The user {} doesn't have any items".format(args["user_name"]) }) response.status_code = 404 return response
def delete_item(args): item = DB.delete_item(args) if item["name"] is None: response = jsonify( {"message": "Item {} not found".format(args["name"])}) response.status_code = 404 return response response = jsonify( {"message": "Item {} deleted successfully".format(item["name"])}) response.status_code = 200 return response
def test_get_item(): item = ["Aged Brie", 2, 0] assert item == DB.get_item("Aged Brie")
def test_get_objeto(): item = AgedBrie("Aged Brie", 2, 0) assert item == DB.get_objeto("Aged Brie")
def update_quality(): return DB.update_quality()
def add_item(args): DB.add_item(args) response = jsonify( {"message": "Item {} added successfully".format(args["name"])}) response.status_code = 201 return response
def get_item_by_sell_in(sell_in): return Service.check(DB.get_item_by_sell_in(sell_in))
def get_item_by_quality(quality): return Service.check(DB.get_item_by_quality(quality))
def get_item_by_name(name): return Service.check(DB.get_item_by_name(name))