Exemplo n.º 1
0
 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
Exemplo n.º 2
0
 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
Exemplo n.º 3
0
 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
Exemplo n.º 4
0
 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
Exemplo n.º 5
0
    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
Exemplo n.º 6
0
    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] }
Exemplo n.º 7
0
 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
Exemplo n.º 8
0
    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")
Exemplo n.º 11
0
 def update_quality():
     return DB.update_quality()
Exemplo n.º 12
0
 def add_item(args):
     DB.add_item(args)
     response = jsonify(
         {"message": "Item {} added successfully".format(args["name"])})
     response.status_code = 201
     return response
Exemplo n.º 13
0
 def get_item_by_sell_in(sell_in):
     return Service.check(DB.get_item_by_sell_in(sell_in))
Exemplo n.º 14
0
 def get_item_by_quality(quality):
     return Service.check(DB.get_item_by_quality(quality))
Exemplo n.º 15
0
 def get_item_by_name(name):
     return Service.check(DB.get_item_by_name(name))