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())
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())
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 ""
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())
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())
def show_ad(id): ad = Ad.find_by_id(id) return render_template("ad.html", ad=ad)
def find_ad(id): return json.dumps(Ad.find_by_id(id).to_dict())
def view_ad(ad_id): return render_template("ad.html", ad=Ad.find_by_id(ad_id))