Skip to content

Commit

Permalink
try to fill db — unluck
Browse files Browse the repository at this point in the history
  • Loading branch information
VLADISLAV.BOBKOV committed Dec 8, 2024
1 parent 98f5af5 commit c483745
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 14 deletions.
23 changes: 14 additions & 9 deletions backend/app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,31 @@
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)
app.register_blueprint(profile_routes)
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")
app.run(host='0.0.0.0', debug=True)
9 changes: 4 additions & 5 deletions database/dump.py → backend/app/utils/dump.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down Expand Up @@ -43,7 +43,6 @@ def create_sample_data():
Admin(_id=ObjectId("64bfe2e10123456789abcdef"), name="Admin2", email="[email protected]", password="adminpass", interaction_history=[interaction_history[1]]).save(),
Admin(_id=ObjectId("64bfe2e20123456789abcdef"), name="Admin3", email="[email protected]", password="adminpass", interaction_history=[interaction_history[2]]).save()
]



def dump_data_to_json(output_file):
Expand Down

0 comments on commit c483745

Please sign in to comment.