def noise(id): result = mongo.db.music.find_one({"_id": ObjectId(id)}) result['_id'] = str(result['_id']) res = ResponseHandle({ "noise":result }) return jsonify(res.get_response())
def article(id): result = mongo.db.article.find_one({"_id": ObjectId(id)}) result['_id'] = str(result['_id']) res = ResponseHandle({ "article":result }) return jsonify(res.get_response())
def delete_news(id): if not id: raise InvalidUsage(status_code=500, payload=set_error(500, "need id")) news = mongo.db.news news.delete_one({"_id": ObjectId(id)}) res = ResponseHandle({"message": "delete succeess"}) return jsonify(res.get_response())
def product(id): result = mongo.db.product.find_one({"type":id}) result["_id"] = str(result["_id"]) res = ResponseHandle({ "product":result }) return jsonify(res.get_response())
def update_news(id): json = request.json if not id: raise InvalidUsage(status_code=500, payload=set_error(500, "need id")) news = mongo.db.news news.update_one({"_id": ObjectId(id)}, {"$set": json}) res = ResponseHandle({"message": "update succeess"}) return jsonify(res.get_response())
def newses(): data = mongo.db.news.find() result = [] for item in data: item["_id"] = str(item["_id"]) result.append(item) res = ResponseHandle({"newses": result}) return jsonify(res.get_response())
def new_news(id): if not id: raise InvalidUsage(status_code=500, payload=set_error(500, "need id")) news = mongo.db.news if id == "new": _id = news.insert_one({"content": "new", "cover": "", "date": None}) res = ResponseHandle({"id": str(_id.inserted_id)}) return jsonify(res.get_response()) else: raise InvalidUsage(status_code=500, payload=set_error(500, "wrong id"))
def products(): data = mongo.db.product.find() result = [] for item in data: item["_id"] = str(item["_id"]) result.append(item) res = ResponseHandle({ "products":result }) return jsonify(res.get_response())
def update_article(id): json = request.json if not id: raise InvalidUsage(status_code=500,payload=set_error(500,"need id")) article = mongo.db.article if 'title' in json or 'content' in json: article.update_one({ "_id": ObjectId(id) },{ "$set":json }) res = ResponseHandle({ "message":"update succeess" }) return jsonify(res.get_response()) else: raise InvalidUsage(status_code=500,payload=set_error(500,"update need both title or content"))
def new_noise(id): if not id: raise InvalidUsage(status_code=500,payload=set_error(500,"need id")) noise = mongo.db.noise if id == "new": _id = noise.insert_one({ "cover" : "", "linkUrl" : "", "date":datetime.datetime.utcnow() }) res = ResponseHandle({ "id":str(_id.inserted_id) }) return jsonify(res.get_response()) else: raise InvalidUsage(status_code=500,payload=set_error(500,"wrong id"))
def articlenew(id): data = request.json if not id: raise InvalidUsage(status_code=500,payload=set_error(500,"need id")) article = mongo.db.article if id == "new": _id = article.insert_one({ "title":"", "content":"", "cover":"", "date":datetime.datetime.utcnow() }) print(_id.inserted_id) res = ResponseHandle({ "id":str(_id.inserted_id) }) print(res.get_response()) return jsonify(res.get_response())