Skip to content

Commit

Permalink
Merge branch 'main' into fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
dyakovri authored Apr 6, 2024
2 parents 1674dd1 + f063932 commit c7f1a55
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions services_backend/routes/button.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand All @@ -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()
Expand Down

0 comments on commit c7f1a55

Please sign in to comment.