add rotuer for get summary donats
This commit is contained in:
parent
e87c1e5718
commit
855465fe8f
@ -7,7 +7,7 @@ from pydantic import PositiveInt
|
||||
from src.core.api_tips_integrate.constants import DONATES_SUM_PERIODS
|
||||
from src.core.api_tips_integrate.schemas import CreateTipSchema
|
||||
from src.core.api_tips_integrate.service import create_payment_link_for_tip_service, \
|
||||
create_payment_link_for_donate_service
|
||||
create_payment_link_for_donate_service, get_donation_period_stat_service
|
||||
from src.core.common.dependencies import http_bearer, data_from_token
|
||||
from src.core.common.schemas import TokenPayloadSchema, PaymentLinkSchema
|
||||
|
||||
@ -35,10 +35,13 @@ async def get_last_donates(
|
||||
path="/summary-payments"
|
||||
)
|
||||
async def get_summary_payments_for_period(
|
||||
token: Annotated[str, Depends(http_bearer)],
|
||||
token: Annotated[HTTPAuthorizationCredentials, Depends(http_bearer)],
|
||||
period: DONATES_SUM_PERIODS,
|
||||
):
|
||||
pass
|
||||
return await get_donation_period_stat_service(
|
||||
token=token.credentials,
|
||||
period=period,
|
||||
)
|
||||
|
||||
|
||||
@router.post(
|
||||
|
@ -36,4 +36,18 @@ class DonationSchema(BaseModel):
|
||||
|
||||
|
||||
class AllDonatesSchema(BaseModel):
|
||||
donates: list[DonationSchema]
|
||||
donates: list[DonationSchema]
|
||||
|
||||
|
||||
class TotalDonationStat(BaseModel):
|
||||
total_amount: float
|
||||
donations_count: int
|
||||
|
||||
class MonthlyDonationStat(BaseModel):
|
||||
date: datetime
|
||||
amount_collected: float
|
||||
donations_count: int
|
||||
|
||||
class DonationPeriodStatSchema(BaseModel):
|
||||
donation_sum: TotalDonationStat
|
||||
donations: list[MonthlyDonationStat]
|
@ -1,6 +1,8 @@
|
||||
import httpx
|
||||
|
||||
from src.core.api_tips_integrate.schemas import CreateTipSchema, AllDonatesSchema, DonationSchema
|
||||
from src.core.api_tips_integrate.constants import DONATES_SUM_PERIODS
|
||||
from src.core.api_tips_integrate.schemas import CreateTipSchema, AllDonatesSchema, DonationSchema, \
|
||||
DonationPeriodStatSchema
|
||||
from src.core.common.constants import DH_ACCOUNTS_API_URL, DH_WIDGETS_API_URL
|
||||
from src.core.common.schemas import TokenPayloadSchema, UserInfoSchema, PaymentLinkSchema
|
||||
|
||||
@ -34,26 +36,38 @@ async def create_payment_link_for_tip_service(
|
||||
if create_tip_schema.text:
|
||||
data["text"] = create_tip_schema.text
|
||||
|
||||
print(DH_WIDGETS_API_URL + f"donat/{user_data.login}")
|
||||
response = await client.post(
|
||||
headers=headers,
|
||||
json=data,
|
||||
url=DH_WIDGETS_API_URL + f"donat/{user_data.login}"
|
||||
)
|
||||
if response.status_code != 200:
|
||||
print(response.json())
|
||||
|
||||
payment_link_schema = PaymentLinkSchema(**response.json())
|
||||
|
||||
return payment_link_schema
|
||||
|
||||
|
||||
async def get_last_donates_by_login():
|
||||
pass
|
||||
async def get_donation_period_stat_service(
|
||||
token: str,
|
||||
period: DONATES_SUM_PERIODS = "24h"
|
||||
) -> DonationPeriodStatSchema:
|
||||
headers = {
|
||||
"accept": "application/json",
|
||||
"Authorization": f"Bearer {token}"
|
||||
}
|
||||
|
||||
params = {"period": period}
|
||||
|
||||
async def get_summary_donates_for_period():
|
||||
pass
|
||||
async with httpx.AsyncClient() as client:
|
||||
response = await client.get(
|
||||
url=DH_WIDGETS_API_URL + "donat/period-stat",
|
||||
headers=headers,
|
||||
params=params
|
||||
)
|
||||
response.raise_for_status()
|
||||
data = response.json()
|
||||
|
||||
return DonationPeriodStatSchema(**data)
|
||||
|
||||
|
||||
async def create_payment_link_for_donate_service(
|
||||
|
Loading…
x
Reference in New Issue
Block a user