From 50fd053186f650f3eb1c1c3ff1032350acb970e6 Mon Sep 17 00:00:00 2001 From: DarkSlein Date: Thu, 20 Mar 2025 15:34:34 +0300 Subject: [PATCH] Added room controller Added async server Added CORS --- Dockerfile | 4 ++-- requirements.txt | 13 ++++++++----- src/app.py | 6 +++++- src/controllers/room_controller.py | 13 +++++++++++++ src/models/room_model.py | 3 +-- 5 files changed, 29 insertions(+), 10 deletions(-) create mode 100644 src/controllers/room_controller.py diff --git a/Dockerfile b/Dockerfile index 591e530..e3db26c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -7,6 +7,6 @@ RUN pip3 install -r requirements.txt COPY . . -ENV FLASK_APP=src/main.py +ENV FLASK_APP=src/app.py -CMD [ "python3", "-m" , "flask", "run", "--host=0.0.0.0", "--port=5000"] \ No newline at end of file +CMD [ "python3", "-m" , "flask", "run", "--host=0.0.0.0", "--port=5004"] \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index 57e19d4..01422e5 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,14 +1,17 @@ annotated-types==0.7.0 -bidict==0.23.1 -blinker==1.8.2 -bson==0.5.10 -click==8.1.8 -colorama==0.4.6 +bidict==0.23.1 +blinker==1.8.2 +bson==0.5.10 +click==8.1.8 +colorama==0.4.6 dnspython==2.7.0 email_validator==2.2.0 +eventlet==0.39.1 Flask==3.0.3 +Flask-Cors==5.0.0 Flask-JWT-Extended==4.7.1 Flask-SocketIO==5.5.1 +greenlet==3.1.1 h11==0.14.0 idna==3.10 importlib_metadata==8.5.0 diff --git a/src/app.py b/src/app.py index 1468e8a..75bfdeb 100644 --- a/src/app.py +++ b/src/app.py @@ -1,3 +1,4 @@ +from flask_cors import CORS from pymongo import MongoClient from flask_jwt_extended import JWTManager @@ -8,11 +9,14 @@ from infra.server import app, socketio from controllers.user_controller import user_blueprint from controllers.reservation_controller import reservation_blueprint from controllers.health_controller import health_blueprint +from controllers.room_controller import room_blueprint +CORS(app) app.config['JWT_SECRET_KEY'] = Config.JWT_SECRET_KEY app.register_blueprint(user_blueprint, url_prefix='/user') app.register_blueprint(reservation_blueprint, url_prefix='/reservation') +app.register_blueprint(room_blueprint, url_prefix='/room') app.register_blueprint(health_blueprint, url_prefix='/health') jwt = JWTManager(app) @@ -26,4 +30,4 @@ else: if __name__ == '__main__': #app.run(debug=True) - socketio.run(app, debug=False) + socketio.run(app, host="192.168.1.178", debug=False) diff --git a/src/controllers/room_controller.py b/src/controllers/room_controller.py new file mode 100644 index 0000000..7d0ace5 --- /dev/null +++ b/src/controllers/room_controller.py @@ -0,0 +1,13 @@ +from flask import Blueprint, request, jsonify + +room_blueprint = Blueprint('room', __name__) + +@room_blueprint.route('/', methods=['GET']) +#@jwt_required() +def list_rooms(): + return jsonify([ + {"id": "67d28e7004bda1d7130c9825", "title": "Маркетинг"}, + {"id": "67d28e7004bda1d7130c9826", "title": "Green"}, + {"id": "67d28e7004bda1d7130c9827", "title": "Конференц-зал"}, + {"id": "67d28e7004bda1d7130c9828", "title": "Dipal"} + ]) \ No newline at end of file diff --git a/src/models/room_model.py b/src/models/room_model.py index e52fead..a0a2367 100644 --- a/src/models/room_model.py +++ b/src/models/room_model.py @@ -1,4 +1,3 @@ class Room: def __init__(self, title, office_id): - self.title = title - self.office_id = office_id \ No newline at end of file + self.title = title \ No newline at end of file