From c483745fd18e3409c0f769ac79daeae1657344f8 Mon Sep 17 00:00:00 2001 From: "VLADISLAV.BOBKOV" Date: Sun, 8 Dec 2024 04:26:53 +0300 Subject: [PATCH] =?UTF-8?q?try=20to=20fill=20db=20=E2=80=94=20unluck?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/app/main.py | 23 ++++++++++++++--------- {database => backend/app/utils}/dump.py | 9 ++++----- 2 files changed, 18 insertions(+), 14 deletions(-) rename {database => backend/app/utils}/dump.py (91%) diff --git a/backend/app/main.py b/backend/app/main.py index d2e7658..79ce131 100644 --- a/backend/app/main.py +++ b/backend/app/main.py @@ -8,17 +8,26 @@ from routes.filter import bp as filter_routes_bp from routes.profile import bp as profile_routes from routes.statistic import bp as statistic_routes +from models import Client +from pymongo import MongoClient +#from utils.dump import create_sample_data app = Flask(__name__) -app.config.from_object(Config) # Загружаем конфигурацию из класса Config +app.config.from_object(Config) CORS(app) -# Отключаем предыдущее соединение (если оно существует) disconnect() - -# Подключение к MongoDB с использованием MONGO_URI из конфигурации connect(host=app.config['MONGO_URI']) +#@app.before_first_request +#def check_collections(): + #client = MongoClient(app.config['MONGO_URI']) + #db = client.get_default_database() + ##collections = db.list_collection_names() + #if not collections: +# pass + ##create_sample_data() + app.register_blueprint(auth_routes_bp) app.register_blueprint(request_routes_bp) app.register_blueprint(filter_routes_bp) @@ -26,8 +35,4 @@ app.register_blueprint(statistic_routes) if __name__ == '__main__': - app.run(host='0.0.0.0', debug=True) - -class Config: - SECRET_KEY = os.getenv("SECRET_KEY", "supersecret") - MONGO_URI = os.getenv("MONGO_URI", "mongodb://mongo:27017/credit_database") \ No newline at end of file + app.run(host='0.0.0.0', debug=True) \ No newline at end of file diff --git a/database/dump.py b/backend/app/utils/dump.py similarity index 91% rename from database/dump.py rename to backend/app/utils/dump.py index cf9ca38..2153cd3 100644 --- a/database/dump.py +++ b/backend/app/utils/dump.py @@ -2,16 +2,16 @@ from mongoengine import connect from datetime import datetime from bson import ObjectId -from backend.app.models import Credit, CreditHistory, CreditRequest, Client, Admin, InteractionHistory +from models import Credit, CreditHistory, CreditRequest, Client, Admin, InteractionHistory connect(db="credit_database", host="localhost", port=27017) def create_sample_data(): credits = [ - Credit(_id=ObjectId("64bfe2e30123456789abcdef"), loan_name="Молодежный", amount=5000, interest_rate=5.5, monthly_payment=150).save(), - Credit(_id=ObjectId("64bfe2e40123456789abcdef"), loan_name="Эконом", amount=15000, interest_rate=4.2, monthly_payment=300).save(), - Credit(_id=ObjectId("64bfe2e50123456789abcdef"), loan_name="Ипотека", amount=200000, interest_rate=3.8, monthly_payment=1200).save() + Credit(_id=ObjectId("64bfe2e30123456789abcdef"), loan_name="Молодежный кредит", amount=5000, interest_rate=5.5, monthly_payment=150, expiration_time = 6).save(), + Credit(_id=ObjectId("64bfe2e40123456789abcdef"), loan_name="Автокредит", amount=15000, interest_rate=4.2, monthly_payment=300, expiration_time = 5).save(), + Credit(_id=ObjectId("64bfe2e50123456789abcdef"), loan_name="Ипотека", amount=200000, interest_rate=3.8, monthly_payment=1200, expiration_time = 4).save() ] credit_history = [ @@ -43,7 +43,6 @@ def create_sample_data(): Admin(_id=ObjectId("64bfe2e10123456789abcdef"), name="Admin2", email="admin2@example.com", password="adminpass", interaction_history=[interaction_history[1]]).save(), Admin(_id=ObjectId("64bfe2e20123456789abcdef"), name="Admin3", email="admin3@example.com", password="adminpass", interaction_history=[interaction_history[2]]).save() ] - def dump_data_to_json(output_file):