From a6308582cb3bafbb60e65007f82289091ccda760 Mon Sep 17 00:00:00 2001 From: Redsandyg Date: Sat, 21 Jun 2025 15:02:21 +0300 Subject: [PATCH] =?UTF-8?q?=D0=A3=D0=B4=D0=B0=D0=BB=D0=B5=D0=BD=D0=BE=20?= =?UTF-8?q?=D0=BF=D0=BE=D0=BB=D0=B5=20agent=5Fcommission=20=D0=B8=D0=B7=20?= =?UTF-8?q?=D0=BC=D0=BE=D0=B4=D0=B5=D0=BB=D0=B8=20CompanyProfileResponse?= =?UTF-8?q?=20=D0=B8=20=D1=81=D0=BE=D0=BE=D1=82=D0=B2=D0=B5=D1=82=D1=81?= =?UTF-8?q?=D1=82=D0=B2=D1=83=D1=8E=D1=89=D0=B8=D1=85=20=D0=BC=D0=B5=D1=81?= =?UTF-8?q?=D1=82=20=D0=B2=20=D0=BA=D0=BE=D0=B4=D0=B5.=20=D0=9E=D0=B1?= =?UTF-8?q?=D0=BD=D0=BE=D0=B2=D0=BB=D0=B5=D0=BD=D1=8B=20=D0=B7=D0=BD=D0=B0?= =?UTF-8?q?=D1=87=D0=B5=D0=BD=D0=B8=D1=8F=20=D0=BA=D0=BE=D0=BC=D0=B8=D1=81?= =?UTF-8?q?=D1=81=D0=B8=D0=B8=20=D0=B2=20=D1=84=D1=83=D0=BD=D0=BA=D1=86?= =?UTF-8?q?=D0=B8=D0=B8=20fill=5Fdb=20=D0=B4=D0=BB=D1=8F=20=D1=81=D0=BE?= =?UTF-8?q?=D0=B7=D0=B4=D0=B0=D0=BD=D0=B8=D1=8F=20=D0=BA=D0=BE=D0=BC=D0=BF?= =?UTF-8?q?=D0=B0=D0=BD=D0=B8=D0=B8.=20=D0=98=D0=B7=D0=BC=D0=B5=D0=BD?= =?UTF-8?q?=D0=B5=D0=BD=D1=8B=20=D1=82=D0=B5=D0=B3=D0=B8=20=D0=B2=20=D1=8D?= =?UTF-8?q?=D0=BD=D0=B4=D0=BF=D0=BE=D0=B8=D0=BD=D1=82=D0=B0=D1=85=20API,?= =?UTF-8?q?=20=D1=83=D0=B1=D1=80=D0=B0=D0=BD=D1=8B=20=D0=BB=D0=B8=D1=88?= =?UTF-8?q?=D0=BD=D0=B8=D0=B5=20=D1=82=D0=B5=D0=B3=D0=B8=20"bff"=20=D0=B4?= =?UTF-8?q?=D0=BB=D1=8F=20=D1=83=D0=BF=D1=80=D0=BE=D1=89=D0=B5=D0=BD=D0=B8?= =?UTF-8?q?=D1=8F=20=D1=81=D1=82=D1=80=D1=83=D0=BA=D1=82=D1=83=D1=80=D1=8B?= =?UTF-8?q?.=20=D0=A3=D0=BB=D1=83=D1=87=D1=88=D0=B5=D0=BD=D0=B0=20=D1=87?= =?UTF-8?q?=D0=B8=D1=82=D0=B0=D0=B5=D0=BC=D0=BE=D1=81=D1=82=D1=8C=20=D0=BA?= =?UTF-8?q?=D0=BE=D0=B4=D0=B0.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bff_models.py | 1 - fill_db.py | 3 +-- main.py | 51 +++++++++++++++++++++++++-------------------------- sql_models.py | 1 - 4 files changed, 26 insertions(+), 30 deletions(-) diff --git a/bff_models.py b/bff_models.py index 2f353fa..906fd84 100644 --- a/bff_models.py +++ b/bff_models.py @@ -145,7 +145,6 @@ class CompanyProfileResponse(BaseModel): name: str key: str commission: float - agent_commission: float class AccountProfileResponse(BaseModel): firstName: Optional[str] = None diff --git a/fill_db.py b/fill_db.py index 6c442b8..9d6d82d 100644 --- a/fill_db.py +++ b/fill_db.py @@ -87,8 +87,7 @@ def fill_db(): # 0. Company company = Company( name="RE: Premium", - commission=10.0, - agent_commission=15.0, + commission=0.0, key="re-premium-key", ) session.add(company) diff --git a/main.py b/main.py index b2cf8f1..f611e58 100644 --- a/main.py +++ b/main.py @@ -79,7 +79,7 @@ app = FastAPI() -@app.post("/token", response_model=Token, tags=["bff", "token"]) +@app.post("/token", response_model=Token, tags=[ "token"]) def login_account_for_access_token( form_data: OAuth2PasswordRequestForm = Depends(), db: Session = Depends(get_db) @@ -103,7 +103,7 @@ def login_account_for_access_token( return Token(access_token=access_token, token_type="bearer") -@app.get("/dashboard/cards", tags=["bff", "dashboard"], response_model=DashboardCardsResponse) +@app.get("/dashboard/cards", tags=[ "dashboard"], response_model=DashboardCardsResponse) def get_dashboard_cards(current_account: Account = Depends(get_current_account), db: Session = Depends(get_db)): """ Возвращает данные для карточек на главной панели (dashboard) пользователя, включая общий доход, выплаты, активных рефералов, ожидающие выплаты и общее количество продаж. @@ -134,7 +134,7 @@ def get_dashboard_cards(current_account: Account = Depends(get_current_account), "totalSales": totalSales } -@app.get("/dashboard/chart/total", tags=["bff", "dashboard"], response_model=DashboardChartTotalResponse) +@app.get("/dashboard/chart/total", tags=[ "dashboard"], response_model=DashboardChartTotalResponse) def get_dashboard_chart_total(current_account: Account = Depends(get_current_account), db: Session = Depends(get_db)): """ Возвращает данные для графика "Общий доход и продажи по датам" на главной панели (dashboard). @@ -155,7 +155,7 @@ def get_dashboard_chart_total(current_account: Account = Depends(get_current_acc ] return DashboardChartTotalResponse(items=data) -@app.get("/dashboard/chart/agent", tags=["bff", "dashboard"], response_model=DashboardChartAgentResponse) +@app.get("/dashboard/chart/agent", tags=[ "dashboard"], response_model=DashboardChartAgentResponse) def get_dashboard_chart_agent(current_account: Account = Depends(get_current_account), db: Session = Depends(get_db)): """ Возвращает данные для графика "Продажи по агентам" на главной панели (dashboard). @@ -185,7 +185,7 @@ def get_dashboard_chart_agent(current_account: Account = Depends(get_current_acc }) return DashboardChartAgentResponse(items=result) -@app.get("/stat/agents", tags=["bff", "stat"], response_model=StatAgentsResponse) +@app.get("/stat/agents", tags=[ "stat"], response_model=StatAgentsResponse) def get_agents_stat( db: Session = Depends(get_db), date_start: str = Query(None), @@ -229,7 +229,7 @@ def get_agents_stat( }) return StatAgentsResponse(items=result) -@app.get("/stat/referrals", tags=["bff", "stat"], response_model=StatReferralsResponse) +@app.get("/stat/referrals", tags=[ "stat"], response_model=StatReferralsResponse) def get_referrals_stat( db: Session = Depends(get_db), date_start: str = Query(None), @@ -262,7 +262,7 @@ def get_referrals_stat( }) return StatReferralsResponse(items=result) -@app.get("/stat/sales", tags=["bff", "stat"], response_model=StatSalesResponse) +@app.get("/stat/sales", tags=[ "stat"], response_model=StatSalesResponse) def get_sales_stat( db: Session = Depends(get_db), date_start: str = Query(None), @@ -298,7 +298,7 @@ def get_sales_stat( }) return StatSalesResponse(items=result) -@app.get("/billing/cards", tags=["bff", "billing"], response_model=BillingCardsResponse) +@app.get("/billing/cards", tags=[ "billing"], response_model=BillingCardsResponse) def get_billing_cards(current_account: Account = Depends(get_current_account), db: Session = Depends(get_db)): """ Возвращает ключевые показатели биллинга для компании, включая общий заработок, общие выплаты и доступные к выводу средства. @@ -321,7 +321,7 @@ def get_billing_cards(current_account: Account = Depends(get_current_account), d "pendingPayouts": pendingPayouts } -@app.get("/billing/payouts/transactions", tags=["bff", "billing"], response_model=BillingPayoutsTransactionsResponse) +@app.get("/billing/payouts/transactions", tags=[ "billing"], response_model=BillingPayoutsTransactionsResponse) def get_billing_payouts_transactions( db: Session = Depends(get_db), date_start: str = Query(None), @@ -361,7 +361,7 @@ def get_billing_payouts_transactions( }) return BillingPayoutsTransactionsResponse(items=result) -@app.get("/billing/chart/stat", tags=["bff", "billing"], response_model=BillingChartStatResponse) +@app.get("/billing/chart/stat", tags=[ "billing"], response_model=BillingChartStatResponse) def get_billing_chart_stat(current_account: Account = Depends(get_current_account), db: Session = Depends(get_db)): """ Возвращает статистику выплат по датам и статусам для компании текущего пользователя. @@ -386,7 +386,7 @@ def get_billing_chart_stat(current_account: Account = Depends(get_current_accoun ] return BillingChartStatResponse(items=data) -@app.get("/billing/chart/pie", tags=["bff", "billing"], response_model=BillingChartPieResponse) +@app.get("/billing/chart/pie", tags=[ "billing"], response_model=BillingChartPieResponse) def get_billing_chart_pie(current_account: Account = Depends(get_current_account), db: Session = Depends(get_db)): """ Возвращает круговую диаграмму статистики выплат по статусам для компании текущего пользователя. @@ -406,7 +406,7 @@ def get_billing_chart_pie(current_account: Account = Depends(get_current_account -@app.get("/account", tags=["bff", "account"], response_model=AccountResponse) +@app.get("/account", tags=[ "account"], response_model=AccountResponse) def get_account(current_account: Account = Depends(get_current_account)): """ Возвращает базовую информацию об аккаунте текущего пользователя (имя и фамилию). @@ -416,7 +416,7 @@ def get_account(current_account: Account = Depends(get_current_account)): "surname": current_account.surname } -@app.get("/account/profile", tags=["bff", "account"], response_model=AccountProfileResponse) +@app.get("/account/profile", tags=[ "account"], response_model=AccountProfileResponse) def get_account_profile(current_account: Account = Depends(get_current_account), db: Session = Depends(get_db)): """ Возвращает полную информацию о профиле аккаунта текущего пользователя, включая данные компании. @@ -434,11 +434,10 @@ def get_account_profile(current_account: Account = Depends(get_current_account), "name": company.name, "key": company.key, "commission": company.commission, - "agent_commission": company.agent_commission } } -@app.post("/account/profile", tags=["bff", "account"], response_model=AccountProfileUpdateResponse) +@app.post("/account/profile", tags=[ "account"], response_model=AccountProfileUpdateResponse) def update_account_profile( req: AccountProfileUpdateRequest, current_account: Account = Depends(get_current_account), @@ -460,7 +459,7 @@ def update_account_profile( db.refresh(current_account) return {"msg": "Профиль обновлён успешно"} -@app.post("/account/password", tags=["bff", "account"], response_model=AccountPasswordChangeResponse) +@app.post("/account/password", tags=[ "account"], response_model=AccountPasswordChangeResponse) def change_account_password( req: AccountPasswordChangeRequest, current_account: Account = Depends(get_current_account), @@ -486,7 +485,7 @@ def change_account_password( # --- Новый функционал для агентских транзакций партнера --- -@app.get("/account/agent-transaction", response_model=List[AgentTransactionResponse], tags=["bff", "account"]) +@app.get("/account/agent-transaction", response_model=List[AgentTransactionResponse], tags=[ "account"]) def get_account_agent_transactions( statuses: Optional[List[TransactionStatus]] = Query(None), date_start: str = Query(None), @@ -543,7 +542,7 @@ def get_account_agent_transactions( -@app.get("/account/auto-approve", tags=["bff", "account"], response_model=AutoApproveSettingsGetResponse) +@app.get("/account/auto-approve", tags=[ "account"], response_model=AutoApproveSettingsGetResponse) def get_auto_approve_settings( current_account: Account = Depends(get_current_account), db: Session = Depends(get_db) @@ -556,7 +555,7 @@ def get_auto_approve_settings( raise HTTPException(status_code=404, detail="Компания не найдена") return {"auto_approve_transactions": company.auto_approve_transactions} -@app.post("/account/auto-approve", tags=["bff", "account"], response_model=AutoApproveSettingsUpdateResponse) +@app.post("/account/auto-approve", tags=[ "account"], response_model=AutoApproveSettingsUpdateResponse) def update_auto_approve_settings( req: AutoApproveSettingsRequest, current_account: Account = Depends(get_current_account), @@ -606,7 +605,7 @@ def update_auto_approve_settings( -@app.post("/account/approve-transactions", tags=["bff", "account"], response_model=ApproveTransactionsResult) +@app.post("/account/approve-transactions", tags=[ "account"], response_model=ApproveTransactionsResult) def approve_agent_transactions( req: ApproveTransactionsRequest, current_account: Account = Depends(get_current_account), @@ -643,7 +642,7 @@ def approve_agent_transactions( # --- Новый функционал для интеграционных токенов --- -@app.get("/account/integration-tokens", tags=["bff", "account"], response_model=List[IntegrationTokenResponse]) +@app.get("/account/integration-tokens", tags=[ "account"], response_model=List[IntegrationTokenResponse]) def get_integration_tokens( current_account: Account = Depends(get_current_account), db: Session = Depends(get_db) @@ -655,7 +654,7 @@ def get_integration_tokens( return tokens # Позволяем FastAPI самостоятельно сериализовать объекты IntegrationToken в IntegrationTokenResponse -@app.post("/account/integration-tokens", tags=["bff", "account"], response_model=IntegrationTokenResponse) +@app.post("/account/integration-tokens", tags=[ "account"], response_model=IntegrationTokenResponse) def create_integration_token( req: IntegrationTokenCreateRequest, current_account: Account = Depends(get_current_account), @@ -688,7 +687,7 @@ def create_integration_token( return response_token -@app.post("/account/integration-tokens/update-description", tags=["bff", "account"], response_model=Dict[str, str]) +@app.post("/account/integration-tokens/update-description", tags=[ "account"], response_model=Dict[str, str]) def update_integration_token_description( req: IntegrationTokenUpdateRequest, current_account: Account = Depends(get_current_account), @@ -711,7 +710,7 @@ def update_integration_token_description( db.refresh(token) return {"msg": "Описание токена обновлено успешно"} -@app.delete("/account/integration-tokens/{token_id}", tags=["bff", "account"], response_model=Dict[str, str]) +@app.delete("/account/integration-tokens/{token_id}", tags=[ "account"], response_model=Dict[str, str]) def delete_integration_token( token_id: int, current_account: Account = Depends(get_current_account), @@ -733,7 +732,7 @@ def delete_integration_token( # --- Категории продаж --- -@app.get("/account/category", tags=["bff", "account"], response_model=List[SaleCategoryResponse]) +@app.get("/category", tags=["category"], response_model=List[SaleCategoryResponse]) def get_sale_categories( current_account: Account = Depends(get_current_account), db: Session = Depends(get_db) @@ -744,7 +743,7 @@ def get_sale_categories( categories = db.exec(select(SaleCategory).where(SaleCategory.company_id == current_account.company_id)).all() return categories -@app.post("/account/category", tags=["bff", "account"], response_model=SaleCategoryResponse) +@app.post("/category", tags=["category"], response_model=SaleCategoryResponse) def create_or_update_sale_category( req: SaleCategoryRequest, current_account: Account = Depends(get_current_account), diff --git a/sql_models.py b/sql_models.py index 2845f17..1e59980 100644 --- a/sql_models.py +++ b/sql_models.py @@ -8,7 +8,6 @@ class Company(SQLModel, table=True): id: Optional[int] = Field(default=None, primary_key=True) name: str commission: float # процент комиссии, который взымается за пользование сервисом - agent_commission: float = Field(default=0.0) # процент от продаж, который начисляется агенту key: str = Field(index=True, unique=True) create_dttm: datetime = Field(default_factory=datetime.utcnow) update_dttm: datetime = Field(default_factory=datetime.utcnow)