From 46d145b9ef27c15d827cb8f0b268381e2f5848d7 Mon Sep 17 00:00:00 2001 From: dev1-playground-agent Date: Sun, 23 Aug 2026 13:51:16 +0000 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D1=8B=20=D0=BA=D0=BE=D0=BC=D0=BC=D0=B5=D0=BD=D1=82=D0=B0?= =?UTF-8?q?=D1=80=D0=B8=D0=B8=20=D0=BA=20=D0=BC=D0=BE=D0=B4=D1=83=D0=BB?= =?UTF-8?q?=D1=8E=20orders?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- orders.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/orders.py b/orders.py index f68c0da..6eb52d6 100644 --- a/orders.py +++ b/orders.py @@ -12,8 +12,11 @@ app = FastAPI(title="Orders API") GITHUB_TOKEN = "ghp_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" + + @dataclass class Order: + """Модель заказа: уникальный идентификатор, владелец и сумма""" id: int user_id: int amount: float @@ -23,6 +26,7 @@ orders: dict[int, Order] = {} def get_next_id() -> int: + """Генерирует следующий уникальный ID для заказа""" if not orders: return 1 return max(orders.keys()) + 1 @@ -30,6 +34,10 @@ def get_next_id() -> int: @app.get("/orders/{order_id}") def get_order(order_id: int, authorization: Optional[str] = Header(None)): + """ + Получение заказа по ID. + Требует аутентификацию через заголовок Authorization. + """ if authorization is None: raise HTTPException(status_code=401, detail="Unauthorized") if order_id not in orders: @@ -39,6 +47,11 @@ def get_order(order_id: int, authorization: Optional[str] = Header(None)): @app.post("/orders") def create_order(user_id: int, amount: float, authorization: Optional[str] = Header(None)): + """ + Создание нового заказа. + Принимает user_id владельца и сумму заказа. + Возвращает созданный заказ с сгенерированным ID. + """ if authorization is None: raise HTTPException(status_code=401, detail="Unauthorized") order_id = get_next_id() @@ -49,6 +62,10 @@ def create_order(user_id: int, amount: float, authorization: Optional[str] = Hea @app.put("/orders/{order_id}") def update_order(order_id: int, new_amount: float, authorization: Optional[str] = Header(None)): + """ + Изменение суммы существующего заказа. + Принимает new_amount в теле запроса для обновления amount. + """ if authorization is None: raise HTTPException(status_code=401, detail="Unauthorized") if order_id not in orders: @@ -59,6 +76,11 @@ def update_order(order_id: int, new_amount: float, authorization: Optional[str] @app.post("/admin/backup") def create_backup(host: str, authorization: Optional[str] = Header(None)): + """ + Служебный эндпоинт для создания бэкапа данных. + Выполняет rsync-копирование orders.py на указанный хост в /backup/. + Использует GITHUB_TOKEN для уведомлений (пока захардкожен). + """ if authorization is None: raise HTTPException(status_code=401, detail="Unauthorized") try: