示例#1
0
def buy_item(user_id, id):
    ad = Ad.find_by_id(id)
    if ad.is_active == 1:
        ad.is_active = 0
    else:
        return "Another user bought this item!"
    ad.buyer_id = user_id
    return json.dumps(ad.save().to_dict())
示例#2
0
def buy_article(user_id, ad_id):
    ad = Ad.find_by_id(ad_id)
    if ad.is_available == 0:
        return "Bad request", 400
    
    ad.is_available = 0
    ad.buyer = user_id
    
    return json.dumps(ad.save().to_dict())
示例#3
0
def delete_ad(user_id, ad_id):
    ad_data = request.get_json(force=True, silent=True)
    if ad_data == None:
        return "Bad request", 400

    ad = Ad.find_by_id(ad_id)
    if ad.creator_id is not user_id:
        return "Forbidden", 403
    
    Ad.delete(ad_id)
    return ""
示例#4
0
def change_ad(user_id, ad_id):
    ad_data = request.get_json(force=True, silent=True)
    if ad_data == None:
        return "Bad request", 400

    ad = Ad.find_by_id(ad_id)
    if ad.creator_id is not user_id:
        return "Forbidden", 403
    
    if "title" in ad_data:
        ad.title = ad_data["title"]
    if "desc" in ad_data:
        ad.desc = ad_data["desc"]
    if "price" in ad_data:
        ad.price = ad_data["price"]
    return json.dumps(ad.save().to_dict())
示例#5
0
def change_ad_info(id):
    ad_data = request.get_json(force=True, silent=True)
    if ad_data == None:
        return "Bad request", 400

    ad = Ad.find_by_id(id)

    if "title" in ad_data:
        ad.title = ad_data["title"]

    if "description" in ad_data:
        ad.description = ad_data["description"]

    if "price" in ad_data:
        ad.price = ad_data["price"]

    if "date" in ad_data:
        ad.date = ad_data["date"]

    return json.dumps(ad.save().to_dict())
示例#6
0
def show_ad(id):
    ad = Ad.find_by_id(id)

    return render_template("ad.html", ad=ad)
示例#7
0
def find_ad(id):
    return json.dumps(Ad.find_by_id(id).to_dict())
示例#8
0
def view_ad(ad_id):
    return render_template("ad.html", ad=Ad.find_by_id(ad_id))