def change_document_data(token): if not man.check_token(token): return jsonify(codes.wrong_token) doc_id = units.int_converter(request.args.get("id")) doc_type = units.int_converter(request.args.get("type")) title = request.args.get("title") description = request.args.get("description") year = units.int_converter(request.args.get("year")) price = units.int_converter(request.args.get("price")) copies = units.int_converter(request.args.get("copies")) authors = request.args.get("authors") bestseller = units.boolean(request.args.get("bestseller")) reference = units.boolean(request.args.get("reference")) publisher = request.args.get("publisher") genre = request.args.get("genre") isbn = request.args.get("isbn") image = request.args.get("image") response = man.update_document(doc_id, doc_type, title, description, year, price, copies, authors, bestseller, reference, publisher, genre, isbn, image) return jsonify(response)
def create_document(token): if not man.check_token(token): return jsonify(codes.wrong_token) doc_type = units.int_converter_with_def_0(request.args.get("type")) title = request.args.get("title") description = request.args.get("description") year = units.int_converter(request.args.get("year")) price = units.int_converter(request.args.get("price")) copies = units.int_converter_with_def_0(request.args.get("copies")) authors = request.args.get("authors") bestseller = units.boolean(request.args.get("bestseller")) reference = units.boolean(request.args.get("reference")) publisher = request.args.get("publisher") genre = request.args.get("genre") isbn = request.args.get("isbn") image = request.args.get("image") if title is None or authors is None or doc_type is None: return jsonify(codes.insufficient_data_to_create_document) response = man.create_document(doc_type, title, description, year, price, copies, authors, bestseller, reference, publisher, genre, isbn, image) if response["ok"]: return jsonify(response) elif response["code"] == 425: return jsonify(codes.document_already_exist) elif response["code"] == 426: return jsonify(codes.invalid_document_data) elif response["code"] == 429: return jsonify(codes.insufficient_data_to_create_document) return jsonify(codes.unknown_error)
def renew_document(token): if not man.check_token(token): return jsonify(codes.wrong_token) doc_id = units.int_converter(request.args.get("doc_id")) user_id = units.int_converter(request.args.get("user_id")) response = man.renew_document(doc_id, user_id) return jsonify(response)
def get_genres(token): if not man.check_token(token): return jsonify(codes.wrong_token) count = units.int_converter(request.args.get("count")) offset = units.int_converter(request.args.get("offset")) response = man.get_genres(count, offset) if response["ok"]: return jsonify(response) return jsonify(codes.unknown_error)
def get_users(token): if not man.check_token(token): return jsonify(codes.wrong_token) debtors = units.boolean(request.args.get("debtors")) count = units.int_converter(request.args.get("count")) offset = units.int_converter(request.args.get("offset")) if debtors: response = man.fetch_debtors(count, offset) else: response = man.fetch_users(count, offset) if response["ok"]: return jsonify(response) return jsonify(codes.unknown_error)
def outstanding_doc_request(token): if not man.check_token(token): return jsonify(codes.wrong_token) doc_id = units.int_converter(request.args.get("id")) response = man.outstanding_request(doc_id) return jsonify(response)
def get_brief_user_info(token): if not man.check_token(token): return jsonify(codes.wrong_token) user_id = units.int_converter(request.args.get("id")) response = man.get_brief_user_info(user_id) return jsonify(response)
def delete_document(token): if not man.check_token(token): return jsonify(codes.wrong_token) doc_id = units.int_converter(request.args.get("id")) response = man.delete_document(doc_id) return jsonify(response)
def search(token): if not man.check_token(token): return jsonify(codes.wrong_token) query = request.args.get("q") user_id = units.int_converter(request.args.get("id")) response = man.search(query, user_id) return jsonify(response)
def get_document(token): if not man.check_token(token): return jsonify(codes.wrong_token) doc_id = units.int_converter(request.args.get("id")) response = man.fetch_document(doc_id) if response["ok"]: return jsonify(response) return jsonify(codes.document_not_exist)
def get_documents(token): if not man.check_token(token): return jsonify(codes.wrong_token) user_id = units.int_converter(request.args.get("id")) for_user = units.int_converter(request.args.get("for_user")) count = units.int_converter(request.args.get("count")) offset = units.int_converter(request.args.get("offset")) genre = request.args.get("genre") if user_id: response = man.fetch_user_taken_books(user_id) elif for_user: response = man.fetch_documents_for_user(for_user) elif genre: response = man.fetch_documents_by_genre(genre) else: response = man.fetch_documents(count, offset) if response["ok"]: return jsonify(response) else: return jsonify(codes.unknown_error)
def change_user_data(token): if not man.check_token(token): return jsonify(codes.wrong_token) user_id = request.args.get("id") email = request.args.get("email") password_hash = request.args.get("passwd_hash") name = request.args.get("name") u_type = units.int_converter(request.args.get("type")) phone = request.args.get("phone") address = request.args.get("address") user_image = request.args.get("user_image") response = man.update_user(user_id, email, password_hash, name, u_type, phone, address, user_image) return jsonify(response)