From f06393266b85e07d652552fa82a474ff8cb886c2 Mon Sep 17 00:00:00 2001 From: Stanislav Roslavtsev Date: Sat, 6 Apr 2024 15:52:28 +0300 Subject: [PATCH] =?UTF-8?q?=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=BB=D0=BE=D0=B3=D0=B8=D0=BA=D0=B8?= =?UTF-8?q?=20=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D1=8B=20patch=20(#49)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Update button.py * Black + isort * Fix tests --------- Co-authored-by: Roman Dyakov --- migrations/versions/660bb7891726_scopes.py | 1 + migrations/versions/6a486347af93_order.py | 1 + .../d35e88f39f85_end-to-end_numbering_fix.py | 1 + .../d6b21dcb2c75_enum_type_button_fix.py | 1 + services_backend/routes/base.py | 2 +- services_backend/routes/button.py | 16 ++++++++++++---- 6 files changed, 17 insertions(+), 5 deletions(-) diff --git a/migrations/versions/660bb7891726_scopes.py b/migrations/versions/660bb7891726_scopes.py index 57a6059..2a4b964 100644 --- a/migrations/versions/660bb7891726_scopes.py +++ b/migrations/versions/660bb7891726_scopes.py @@ -5,6 +5,7 @@ Create Date: 2023-03-16 14:38:26.163590 """ + import sqlalchemy as sa from alembic import op diff --git a/migrations/versions/6a486347af93_order.py b/migrations/versions/6a486347af93_order.py index bd87bed..06d4f50 100644 --- a/migrations/versions/6a486347af93_order.py +++ b/migrations/versions/6a486347af93_order.py @@ -5,6 +5,7 @@ Create Date: 2023-02-11 10:18:11.179485 """ + import sqlalchemy as sa from alembic import op diff --git a/migrations/versions/d35e88f39f85_end-to-end_numbering_fix.py b/migrations/versions/d35e88f39f85_end-to-end_numbering_fix.py index daf1b6a..a5bdf3d 100644 --- a/migrations/versions/d35e88f39f85_end-to-end_numbering_fix.py +++ b/migrations/versions/d35e88f39f85_end-to-end_numbering_fix.py @@ -5,6 +5,7 @@ Create Date: 2023-04-09 11:28:59.326067 """ + import operator import sqlalchemy as sa diff --git a/migrations/versions/d6b21dcb2c75_enum_type_button_fix.py b/migrations/versions/d6b21dcb2c75_enum_type_button_fix.py index 51884e3..f62995f 100644 --- a/migrations/versions/d6b21dcb2c75_enum_type_button_fix.py +++ b/migrations/versions/d6b21dcb2c75_enum_type_button_fix.py @@ -5,6 +5,7 @@ Create Date: 2023-04-11 14:21:54.007129 """ + import sqlalchemy as sa from alembic import op diff --git a/services_backend/routes/base.py b/services_backend/routes/base.py index 873e0c1..3e95e11 100644 --- a/services_backend/routes/base.py +++ b/services_backend/routes/base.py @@ -18,7 +18,7 @@ description='Программный интерфейс управления списком сервисов в приложении Твой ФФ!', version=__version__, # Настраиваем интернет документацию - root_path=settings.ROOT_PATH if __version__ != 'dev' else '/', + root_path=settings.ROOT_PATH if __version__ != 'dev' else '', docs_url=None if __version__ != 'dev' else '/docs', redoc_url=None, ) diff --git a/services_backend/routes/button.py b/services_backend/routes/button.py index 3eae6d7..7ccef5f 100644 --- a/services_backend/routes/button.py +++ b/services_backend/routes/button.py @@ -152,10 +152,14 @@ def update_button( Необходимые scopes: `services.button.update` """ logger.info(f"User {user.get('id')} triggered create_category") - query = db.session.query(Button).filter(Button.id == button_id) + query = db.session.query(Button).filter(Category.id == category_id).filter(Button.id == button_id) button = query.one_or_none() last_button = ( - db.session.query(Button).filter(Button.category_id == category_id).order_by(Button.order.desc()).first() + db.session.query(Button) + .filter(Category.id == category_id) + .filter(Button.category_id == category_id) + .order_by(Button.order.desc()) + .first() ) category = db.session.query(Category).filter(Category.id == category_id).one_or_none() @@ -177,9 +181,13 @@ def update_button( if button_inp.order < 1: raise HTTPException(status_code=400, detail="Order can`t be less than 1") if button.order > button_inp.order: - db.session.query(Button).filter(Button.order < button.order).update({"order": Button.order + 1}) + db.session.query(Button).filter(Category.id == category_id).filter(Button.order < button.order).update( + {"order": Button.order + 1} + ) elif button.order < button_inp.order: - db.session.query(Button).filter(Button.order > button.order).update({"order": Button.order - 1}) + db.session.query(Button).filter(Category.id == category_id).filter(Button.order > button.order).update( + {"order": Button.order - 1} + ) query.update(button_inp.dict(exclude_unset=True, exclude_none=True)) db.session.flush()