예제 #1
0
def delete():
    productService = ProductService()

    productId = request.args.get("id")
    if productId is None:
        return ("forbidden", 403)

    result = json.dumps({"successful": productService.delete(productId)})

    productService.dispose()
    return (result, 200)
예제 #2
0
def find():
    productService = ProductService()

    productId = request.args.get("id")
    if productId is None:
        return None

    product = productService.find(productId)
    result = json.dumps(product.dicted())

    productService.dispose()

    return (result, 200)
예제 #3
0
def modify():
    productService = ProductService()

    flag = False

    try:
        product = Product.dict2Obj(json.loads(request.data))
        flag = productService.modify(product)
    except:
        return ("forbidden", 403)

    result = json.dumps({"successful": flag})

    productService.dispose()
    return (result, 200)
예제 #4
0
def findWarning():
    productService = ProductService()

    num = request.args.get("num")
    if num is None:
        return None

    products = productService.findWarning(int(num))

    result = []
    for product in products:
        result.append(product.dicted())

    productService.dispose()

    return (json.dumps(result), 200)
예제 #5
0
def index():
    productService = ProductService()

    currentIndex = request.args.get("page")
    if currentIndex is None:
        return ("forbidden", 403)

    lastIndex = math.ceil(productService.count() / float(pageSize))

    products = productService.list(int(currentIndex) - 1, pageSize)

    result = []
    for product in products:
        result.append(product.dicted())

    result = json.dumps({
        "currentIndex": currentIndex,
        "lastIndex": lastIndex,
        "products": result
    })

    productService.dispose()
    return (result, 200)