Удалено поле agent_commission из модели CompanyProfileResponse и соответствующих мест в коде. Обновлены значения комиссии в функции fill_db для создания компании. Изменены теги в эндпоинтах API, убраны лишние теги "bff" для упрощения структуры. Улучшена читаемость кода.
This commit is contained in:
parent
9157570e58
commit
a6308582cb
@ -145,7 +145,6 @@ class CompanyProfileResponse(BaseModel):
|
|||||||
name: str
|
name: str
|
||||||
key: str
|
key: str
|
||||||
commission: float
|
commission: float
|
||||||
agent_commission: float
|
|
||||||
|
|
||||||
class AccountProfileResponse(BaseModel):
|
class AccountProfileResponse(BaseModel):
|
||||||
firstName: Optional[str] = None
|
firstName: Optional[str] = None
|
||||||
|
|||||||
@ -87,8 +87,7 @@ def fill_db():
|
|||||||
# 0. Company
|
# 0. Company
|
||||||
company = Company(
|
company = Company(
|
||||||
name="RE: Premium",
|
name="RE: Premium",
|
||||||
commission=10.0,
|
commission=0.0,
|
||||||
agent_commission=15.0,
|
|
||||||
key="re-premium-key",
|
key="re-premium-key",
|
||||||
)
|
)
|
||||||
session.add(company)
|
session.add(company)
|
||||||
|
|||||||
51
main.py
51
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(
|
def login_account_for_access_token(
|
||||||
form_data: OAuth2PasswordRequestForm = Depends(),
|
form_data: OAuth2PasswordRequestForm = Depends(),
|
||||||
db: Session = Depends(get_db)
|
db: Session = Depends(get_db)
|
||||||
@ -103,7 +103,7 @@ def login_account_for_access_token(
|
|||||||
return Token(access_token=access_token, token_type="bearer")
|
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)):
|
def get_dashboard_cards(current_account: Account = Depends(get_current_account), db: Session = Depends(get_db)):
|
||||||
"""
|
"""
|
||||||
Возвращает данные для карточек на главной панели (dashboard) пользователя, включая общий доход, выплаты, активных рефералов, ожидающие выплаты и общее количество продаж.
|
Возвращает данные для карточек на главной панели (dashboard) пользователя, включая общий доход, выплаты, активных рефералов, ожидающие выплаты и общее количество продаж.
|
||||||
@ -134,7 +134,7 @@ def get_dashboard_cards(current_account: Account = Depends(get_current_account),
|
|||||||
"totalSales": totalSales
|
"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)):
|
def get_dashboard_chart_total(current_account: Account = Depends(get_current_account), db: Session = Depends(get_db)):
|
||||||
"""
|
"""
|
||||||
Возвращает данные для графика "Общий доход и продажи по датам" на главной панели (dashboard).
|
Возвращает данные для графика "Общий доход и продажи по датам" на главной панели (dashboard).
|
||||||
@ -155,7 +155,7 @@ def get_dashboard_chart_total(current_account: Account = Depends(get_current_acc
|
|||||||
]
|
]
|
||||||
return DashboardChartTotalResponse(items=data)
|
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)):
|
def get_dashboard_chart_agent(current_account: Account = Depends(get_current_account), db: Session = Depends(get_db)):
|
||||||
"""
|
"""
|
||||||
Возвращает данные для графика "Продажи по агентам" на главной панели (dashboard).
|
Возвращает данные для графика "Продажи по агентам" на главной панели (dashboard).
|
||||||
@ -185,7 +185,7 @@ def get_dashboard_chart_agent(current_account: Account = Depends(get_current_acc
|
|||||||
})
|
})
|
||||||
return DashboardChartAgentResponse(items=result)
|
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(
|
def get_agents_stat(
|
||||||
db: Session = Depends(get_db),
|
db: Session = Depends(get_db),
|
||||||
date_start: str = Query(None),
|
date_start: str = Query(None),
|
||||||
@ -229,7 +229,7 @@ def get_agents_stat(
|
|||||||
})
|
})
|
||||||
return StatAgentsResponse(items=result)
|
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(
|
def get_referrals_stat(
|
||||||
db: Session = Depends(get_db),
|
db: Session = Depends(get_db),
|
||||||
date_start: str = Query(None),
|
date_start: str = Query(None),
|
||||||
@ -262,7 +262,7 @@ def get_referrals_stat(
|
|||||||
})
|
})
|
||||||
return StatReferralsResponse(items=result)
|
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(
|
def get_sales_stat(
|
||||||
db: Session = Depends(get_db),
|
db: Session = Depends(get_db),
|
||||||
date_start: str = Query(None),
|
date_start: str = Query(None),
|
||||||
@ -298,7 +298,7 @@ def get_sales_stat(
|
|||||||
})
|
})
|
||||||
return StatSalesResponse(items=result)
|
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)):
|
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
|
"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(
|
def get_billing_payouts_transactions(
|
||||||
db: Session = Depends(get_db),
|
db: Session = Depends(get_db),
|
||||||
date_start: str = Query(None),
|
date_start: str = Query(None),
|
||||||
@ -361,7 +361,7 @@ def get_billing_payouts_transactions(
|
|||||||
})
|
})
|
||||||
return BillingPayoutsTransactionsResponse(items=result)
|
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)):
|
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)
|
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)):
|
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)):
|
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
|
"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)):
|
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,
|
"name": company.name,
|
||||||
"key": company.key,
|
"key": company.key,
|
||||||
"commission": company.commission,
|
"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(
|
def update_account_profile(
|
||||||
req: AccountProfileUpdateRequest,
|
req: AccountProfileUpdateRequest,
|
||||||
current_account: Account = Depends(get_current_account),
|
current_account: Account = Depends(get_current_account),
|
||||||
@ -460,7 +459,7 @@ def update_account_profile(
|
|||||||
db.refresh(current_account)
|
db.refresh(current_account)
|
||||||
return {"msg": "Профиль обновлён успешно"}
|
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(
|
def change_account_password(
|
||||||
req: AccountPasswordChangeRequest,
|
req: AccountPasswordChangeRequest,
|
||||||
current_account: Account = Depends(get_current_account),
|
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(
|
def get_account_agent_transactions(
|
||||||
statuses: Optional[List[TransactionStatus]] = Query(None),
|
statuses: Optional[List[TransactionStatus]] = Query(None),
|
||||||
date_start: str = 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(
|
def get_auto_approve_settings(
|
||||||
current_account: Account = Depends(get_current_account),
|
current_account: Account = Depends(get_current_account),
|
||||||
db: Session = Depends(get_db)
|
db: Session = Depends(get_db)
|
||||||
@ -556,7 +555,7 @@ def get_auto_approve_settings(
|
|||||||
raise HTTPException(status_code=404, detail="Компания не найдена")
|
raise HTTPException(status_code=404, detail="Компания не найдена")
|
||||||
return {"auto_approve_transactions": company.auto_approve_transactions}
|
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(
|
def update_auto_approve_settings(
|
||||||
req: AutoApproveSettingsRequest,
|
req: AutoApproveSettingsRequest,
|
||||||
current_account: Account = Depends(get_current_account),
|
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(
|
def approve_agent_transactions(
|
||||||
req: ApproveTransactionsRequest,
|
req: ApproveTransactionsRequest,
|
||||||
current_account: Account = Depends(get_current_account),
|
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(
|
def get_integration_tokens(
|
||||||
current_account: Account = Depends(get_current_account),
|
current_account: Account = Depends(get_current_account),
|
||||||
db: Session = Depends(get_db)
|
db: Session = Depends(get_db)
|
||||||
@ -655,7 +654,7 @@ def get_integration_tokens(
|
|||||||
return tokens # Позволяем FastAPI самостоятельно сериализовать объекты IntegrationToken в IntegrationTokenResponse
|
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(
|
def create_integration_token(
|
||||||
req: IntegrationTokenCreateRequest,
|
req: IntegrationTokenCreateRequest,
|
||||||
current_account: Account = Depends(get_current_account),
|
current_account: Account = Depends(get_current_account),
|
||||||
@ -688,7 +687,7 @@ def create_integration_token(
|
|||||||
|
|
||||||
return response_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(
|
def update_integration_token_description(
|
||||||
req: IntegrationTokenUpdateRequest,
|
req: IntegrationTokenUpdateRequest,
|
||||||
current_account: Account = Depends(get_current_account),
|
current_account: Account = Depends(get_current_account),
|
||||||
@ -711,7 +710,7 @@ def update_integration_token_description(
|
|||||||
db.refresh(token)
|
db.refresh(token)
|
||||||
return {"msg": "Описание токена обновлено успешно"}
|
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(
|
def delete_integration_token(
|
||||||
token_id: int,
|
token_id: int,
|
||||||
current_account: Account = Depends(get_current_account),
|
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(
|
def get_sale_categories(
|
||||||
current_account: Account = Depends(get_current_account),
|
current_account: Account = Depends(get_current_account),
|
||||||
db: Session = Depends(get_db)
|
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()
|
categories = db.exec(select(SaleCategory).where(SaleCategory.company_id == current_account.company_id)).all()
|
||||||
return categories
|
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(
|
def create_or_update_sale_category(
|
||||||
req: SaleCategoryRequest,
|
req: SaleCategoryRequest,
|
||||||
current_account: Account = Depends(get_current_account),
|
current_account: Account = Depends(get_current_account),
|
||||||
|
|||||||
@ -8,7 +8,6 @@ class Company(SQLModel, table=True):
|
|||||||
id: Optional[int] = Field(default=None, primary_key=True)
|
id: Optional[int] = Field(default=None, primary_key=True)
|
||||||
name: str
|
name: str
|
||||||
commission: float # процент комиссии, который взымается за пользование сервисом
|
commission: float # процент комиссии, который взымается за пользование сервисом
|
||||||
agent_commission: float = Field(default=0.0) # процент от продаж, который начисляется агенту
|
|
||||||
key: str = Field(index=True, unique=True)
|
key: str = Field(index=True, unique=True)
|
||||||
create_dttm: datetime = Field(default_factory=datetime.utcnow)
|
create_dttm: datetime = Field(default_factory=datetime.utcnow)
|
||||||
update_dttm: datetime = Field(default_factory=datetime.utcnow)
|
update_dttm: datetime = Field(default_factory=datetime.utcnow)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user