-
Notifications
You must be signed in to change notification settings - Fork 2
updated swagger descriptions #148
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
04a0051
1823ae1
19e49cc
f5cab65
d611b28
7619413
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,3 @@ | ||
| from auth_lib.fastapi import UnionAuth | ||
| from fastapi import APIRouter, Depends, Query | ||
| from fastapi_sqlalchemy import db | ||
|
|
@@ -10,19 +10,29 @@ | |
| from rental_backend.settings import Settings, get_settings | ||
| from rental_backend.utils.action import ActionLogger | ||
|
|
||
|
|
||
| settings: Settings = get_settings() | ||
| item = APIRouter(prefix="/item", tags=["Items"]) | ||
|
|
||
|
|
||
| @item.get("", response_model=list[ItemGet]) | ||
| async def get_items(type_id: int = Query(None), user=Depends(UnionAuth())) -> list[ItemGet]: | ||
| """ | ||
| Retrieves a list of items. If `type_id` is specified, only items of that type are returned. | ||
| Возвращает список предметов. При указании `type_id` возвращаются только предметы заданного типа. | ||
|
|
||
| Условия: | ||
| - Пользователь должен быть аутентифицирован | ||
|
Comment on lines
+22
to
+23
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. убрать |
||
|
|
||
| Скоупы: | ||
| - отсутствуют (доступно любому авторизованному пользователю) | ||
|
|
||
| Параметры: | ||
| - `type_id` — (необязательный) идентификатор типа предмета для фильтрации | ||
|
|
||
| - **type_id**: The ID of the item type (optional). | ||
| Возвращает: | ||
| - список объектов `Item` | ||
|
|
||
| Returns a list of items. | ||
| Ошибки: | ||
| - отсутствуют | ||
|
Comment on lines
+34
to
+35
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. аналогично |
||
| """ | ||
| query = Item.query(session=db.session) | ||
| if type_id is not None: | ||
|
|
@@ -34,15 +44,27 @@ | |
| @item.post("", response_model=ItemGet) | ||
| async def create_item(item: ItemPost, user=Depends(UnionAuth(scopes=["rental.item.create"]))) -> ItemGet: | ||
| """ | ||
| Creates a new item. | ||
| Создает новый предмет. | ||
|
|
||
| Scopes: `["rental.item.create"]` | ||
| Перед созданием проверяется, существует ли тип предмета с указанным `type_id`. | ||
| После успешного создания действие логируется как `CREATE_ITEM`. | ||
|
|
||
| - **item**: The data for the new item. | ||
| Условия: | ||
| - Пользователь должен быть аутентифицирован | ||
| - Пользователь должен иметь право на создание предметов | ||
| - Тип предмета с указанным `type_id` должен существовать | ||
|
|
||
| Returns the created item. | ||
| Скоупы: | ||
| - `rental.item.create` | ||
|
|
||
| Raises **ObjectNotFound** if the item type with the specified `type_id` is not found. | ||
| Параметры: | ||
| - `item` — данные нового предмета | ||
|
Comment on lines
+60
to
+61
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. это неправда, там параметры type_id и is_available |
||
|
|
||
| Возвращает: | ||
| - созданный объект `Item` | ||
|
|
||
| Ошибки: | ||
| - `ObjectNotFound` — тип предмета с указанным `type_id` не найден | ||
|
Comment on lines
+66
to
+67
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. вот, в комментах выше что-то такое тоже надо делать |
||
| """ | ||
| item_type = ItemType.get(item.type_id, session=db.session) | ||
| if item_type is None: | ||
|
|
@@ -65,16 +87,28 @@ | |
| user=Depends(UnionAuth(scopes=["rental.item.patch"])), | ||
| ) -> ItemGet: | ||
| """ | ||
| Updates the availability status of an item by its ID. | ||
| Обновляет статус доступности предмета по его идентификатору. | ||
|
|
||
| Эндпоинт позволяет изменить только поле `is_available`. | ||
| После успешного обновления действие логируется как `UPDATE_ITEM`. | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. логируется в event, из контекста это неочевидно |
||
|
|
||
| Условия: | ||
| - Пользователь должен быть аутентифицирован | ||
| - Пользователь должен иметь право на изменение предметов | ||
| - Предмет с указанным `id` должен существовать | ||
|
Comment on lines
+95
to
+98
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. аналогично убрать |
||
|
|
||
| Scopes: `["rental.item.patch"]` | ||
| Скоупы: | ||
| - `rental.item.patch` | ||
|
|
||
| - **id**: The ID of the item. | ||
| - **is_available**: The new availability status for the item. | ||
| Параметры: | ||
| - `id` — идентификатор предмета | ||
| - `is_available` — новое значение доступности предмета | ||
|
|
||
| Returns the updated item. | ||
| Возвращает: | ||
| - обновленный объект `Item` | ||
|
|
||
| Raises **ObjectNotFound** if the item with the specified ID is not found. | ||
| Ошибки: | ||
| - `ObjectNotFound` — предмет с указанным `id` не найден | ||
| """ | ||
| item = Item.query(session=db.session).filter(Item.id == id).one_or_none() | ||
| if item is not None: | ||
|
|
@@ -95,15 +129,34 @@ | |
| id: int, user=Depends(UnionAuth(scopes=["rental.item.delete"], allow_none=False)) | ||
| ) -> StatusResponseModel: | ||
| """ | ||
| Deletes an item by its ID. | ||
| Удаляет предмет по его идентификатору. | ||
|
|
||
| Scopes: `["rental.item.delete"]` | ||
| Перед удалением проверяется, что с предметом не связано активных, | ||
| зарезервированных или просроченных сессий аренды. | ||
| Если такие сессии существуют — удаление запрещено. | ||
|
|
||
| - **id**: The ID of the item. | ||
| При успешном удалении: | ||
| - удаляется сам предмет | ||
| - удаляются связанные сессии аренды (если они не помечены как удалённые) | ||
| - удаляются связанные страйки и события | ||
| - действие логируется как `DELETE_ITEM` | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. логируется в event, из контекста это неочевидно |
||
|
|
||
| Returns a status response. | ||
| Условия: | ||
| - Пользователь должен быть аутентифицирован | ||
| - Пользователь должен иметь право на удаление предметов | ||
|
Comment on lines
+145
to
+146
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. только это убрать, про статусы оставить, там правильно |
||
| - У предмета не должно быть сессий в статусах ACTIVE / RESERVED / OVERDUE | ||
|
|
||
| Raises **ObjectNotFound** if the item with the specified ID is not found. | ||
| Скоупы: | ||
| - `rental.item.delete` | ||
|
|
||
| Параметры: | ||
| - `id` — идентификатор предмета | ||
|
|
||
| Возвращает: | ||
| - объект `StatusResponseModel` со статусом удаления | ||
|
|
||
| Ошибки: | ||
| - `ObjectNotFound` — предмет не найден или удаление запрещено из-за активных сессий | ||
| """ | ||
| rental_sessions = db.session.query(RentalSession).filter(RentalSession.item_id == id) | ||
| session = rental_sessions.filter( | ||
|
|
@@ -134,7 +187,22 @@ | |
| @item.get("/{id}", response_model=ItemGet) | ||
| async def get_item(id: int) -> ItemGet: | ||
| """ | ||
| Получает предмет по его идентификатору. | ||
| Возвращает предмет по его идентификатору. | ||
|
|
||
| Условия: | ||
| - отсутствуют (доступно без авторизации) | ||
|
|
||
| Скоупы: | ||
| - отсутствуют | ||
|
Comment on lines
+192
to
+196
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. условия и скоупы удалить, зачем про них писать если не требуется? |
||
|
|
||
| Параметры: | ||
| - `id` — идентификатор предмета | ||
|
|
||
| Возвращает: | ||
| - объект `Item` | ||
|
|
||
| Ошибки: | ||
| - возможна ошибка валидации, если предмет с указанным `id` не найден | ||
| """ | ||
| item = Item.get(id=id, session=db.session) | ||
| return ItemGet.model_validate(item) | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ахаххаха, забавно)
попробуй как минимум ввести -100
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ошибки отсутствуют лучше не писать никогда))