payHookIos / server /pydanticModel.py
rogerxavier's picture
Update server/pydanticModel.py
ecc6c96 verified
raw
history blame
5.12 kB
from pydantic import BaseModel,field_validator,Field
from fastapi import Query
from typing import List, Optional, Any
# 定义fastapi请求参数模型
class signUp(BaseModel):
email: str
password: str
# 可选参数
expiredAt: int = Query(default=0, alias="expiredAt")
balance: int = Query(default=0, alias="balance")
ec: int = Query(default=200, alias="ec")
@field_validator('email')
#确保password不为''
def check_email(cls, v):
if v == '':
raise ValueError('email cannot be an empty string')
return v
@field_validator('password')
# 确保password不为''
def check_password(cls, v):
if v == '':
raise ValueError('password cannot be an empty string')
return v
class accountDelete(BaseModel):
email: str
password: str
# 可选参数
expiredAt: int = Query(default=0, alias="expiredAt")
balance: int = Query(default=0, alias="balance")
ec: int = Query(default=200, alias="ec")
@field_validator('email')
#确保password不为''
def check_email(cls, v):
if v == '':
raise ValueError('email cannot be an empty string')
return v
@field_validator('password')
# 确保password不为''
def check_password(cls, v):
if v == '':
raise ValueError('password cannot be an empty string')
return v
class signIn(BaseModel):
email: str
password: str
# 可选参数
expiredAt: int = Query(default=0, alias="expiredAt")
balance: int = Query(default=0, alias="balance")
ec: int = Query(default=200, alias="ec")
@field_validator('email')
# 确保password不为''
def check_email(cls, v):
if v == '':
raise ValueError('email cannot be an empty string')
return v
@field_validator('password')
# 确保password不为''
def check_password(cls, v):
if v == '':
raise ValueError('password cannot be an empty string')
return v
class SKUDetail(BaseModel):
sku_id: Optional[str] = None
price: Optional[str] = None
count: Optional[int] = None
name: Optional[str] = None
album_id: Optional[str] = None
pic: Optional[str] = None
stock: Optional[str] = None
post_id: Optional[str] = None
class AfdianOrderDetail(BaseModel):
out_trade_no: Optional[str] = Field(default=None, alias="out_trade_no")
user_id: Optional[str] = Field(default=None, alias="user_id")
plan_id: Optional[str] = Field(default=None, alias="plan_id")
title: Optional[str] = Field(default=None, alias="title") #just afdian test have
month: Optional[int] = Field(default=None, alias="month")
total_amount: Optional[int] = Field(default=None, alias="total_amount") # 这里精髓在于pydantic会在能转换下自动转int 但字符串 "6.60" 将无法转换为整数,因此会导致 422 错误 因此商品可以回调而兑换码422
show_amount: Optional[str] = Field(default=None, alias="show_amount")
status: Optional[int] = Field(default=None, alias="status")
remark: Optional[str] = Field(default=None, alias="remark")
redeem_id: Optional[str] = Field(default=None, alias="redeem_id")
product_type: Optional[int] = Field(default=None, alias="product_type")
discount: Optional[str] = Field(default=None, alias="discount")
sku_detail: Optional[List[SKUDetail]] = Field(default=[], alias="sku_detail") #兼容afdian test 请求
create_time: Optional[int] = Field(default=None, alias="create_time")
plan_title: Optional[str] = Field(default=None, alias="plan_title")
user_private_id: Optional[str] = Field(default=None, alias="user_private_id")
address_person: Optional[str] = Field(default=None, alias="address_person")
address_phone: Optional[str] = Field(default=None, alias="address_phone")
address_address: Optional[str] = Field(default=None, alias="address_address")
custom_order_id: Optional[str] = Field(default=None, alias="custom_order_id")
class AfdianOrderData(BaseModel):
type: str
order: AfdianOrderDetail
class AfdianHookJson(BaseModel):
ec: int
em: str
data: AfdianOrderData
class AfdianResp(BaseModel):
ec: Any
#根据plan中的价格和时间相应减少balance和增加expiredAt
class userPlan(BaseModel):
price: int
duration_seconds: int
email: str #订阅plan的用户
password: str #请求purchase接口用户的password,保证只有用户本身可以请求这个接口防止滥用
@field_validator('price')
# 确保password不为''
def check_price(cls, v):
if v < 0:
raise ValueError('price can not < 0')
return v
@field_validator('duration_seconds')
# 确保password不为''
def check_duration_seconds(cls, v):
if v < 0:
raise ValueError('duration_seconds can not < 0')
return v
@field_validator('email')
# 确保password不为''
def check_email(cls, v):
if v == '':
raise ValueError('email cannot be an empty string')
return v