示例#1
0
def get_products_ep(user, archived, locked):
    if not has_required_role(user, 'product manager'):
        return 'Недопустимо для текущего пользователя', 403

    products = get_products(archived, locked)

    return [ProductModel(item).as_json() for item in products], 200
示例#2
0
 def __init__(self, lunchbox, products):
     self.id = lunchbox.id
     self.name = lunchbox.name
     self.price = lunchbox.price
     self.archived = lunchbox.archived
     self.locked = lunchbox.locked
     self.stock = lunchbox.stock
     self.products = [ProductModel(x) for x in products]
示例#3
0
def lock_product_with_id_ep(user, id):
    if not has_required_role(user, 'product manager'):
        return 'Недопустимо для текущего пользователя', 403

    try:
        product = lock_product_with_id(id)
        return ProductModel(product).as_json(), 200
    except BaseLBSException as e:
        return e.response()
示例#4
0
def get_lunchbox_products_with_id_ep(id, user):
    if not has_required_role(user, 'lunchbox manager'):
        return 'Недопустимо для текущего пользователя', 403

    try:
        products = get_lunchbox_products_with_id(id)
        return [ProductModel(x).as_json() for x in products], 200
    except BaseLBSException as e:
        return e.response()
示例#5
0
def add_product_ep(user, body):
    if not has_required_role(user, 'product manager'):
        return 'Недопустимо для текущего пользователя', 403

    model = ProductEditModel(body)
    try:
        product = add_product(model)
        return ProductModel(product).as_json(), 200
    except BaseLBSException as e:
        return e.response()