Skip to content

добавлена сортировка и фильтр is_available для GET /item#150

Merged
petrCher merged 7 commits into
mainfrom
add_sort
Apr 30, 2026
Merged

добавлена сортировка и фильтр is_available для GET /item#150
petrCher merged 7 commits into
mainfrom
add_sort

Conversation

@businkv

@businkv businkv commented Apr 28, 2026

Copy link
Copy Markdown
Contributor

Изменения

Добавлена сортировка предметов по полю
Добавлено направление сортировки по asc/desc
Добавлен флаг is_available

Детали реализации

В get_items добавлено order_by: str = "id", order: str = "asc", is_available: bool = Query(None)
сортировка через getattr(Item, order_by, Item.id) с проверкой на asc/desc

@github-actions

Copy link
Copy Markdown

💩 Code linting failed, use black and isort to fix it.

@github-actions

github-actions Bot commented Apr 28, 2026

Copy link
Copy Markdown

Summary

Tests Skipped Failures Errors Time
131 0 💤 0 ❌ 0 🔥 18.872s ⏱️

@businkv businkv self-assigned this Apr 29, 2026
Comment thread rental_backend/routes/item.py Outdated
Retrieves a list of items. If `type_id` is specified, only items of that type are returned.

- **type_id**: The ID of the item type (optional).
- **order_by**: Sort field (default: id).

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

обнови доку к ручке

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

надо написать что происходит в логике, просто сейчас непонятно как параметры связаны между собой, то есть для сортировки по возрастанию например должен быть указан параметр по чему сортировать

Comment thread rental_backend/routes/item.py Outdated
column = getattr(Item, order_by, Item.id)
if order == "desc":
query = query.order_by(column.desc())
else:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

у тебя три варианта, asс desc и None
так что такой елз делать не надо

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

просто elif на asc

Comment thread rental_backend/routes/item.py Outdated
if is_available is not None:
query = query.filter(Item.is_available == is_available)

if order_by is not None and order is not None:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

а зачем проверка на order not null?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

я бы вообще убрал всю эту проверку для order_by и order
ты же все равно делаешь getattr и в случае несуществования order_by будет задаваться сортировка по айди, что верно

@github-actions

Copy link
Copy Markdown

💩 Code linting failed, use black and isort to fix it.

@petrCher petrCher merged commit 01506bb into main Apr 30, 2026
2 checks passed
@petrCher petrCher deleted the add_sort branch April 30, 2026 14:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Сделать систему настройки порядка вывода айтемов в меню

2 participants