chore: initialize tuhui repository
This commit is contained in:
1
backend/app/schemas/__init__.py
Normal file
1
backend/app/schemas/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
"""Pydantic Schemas"""
|
||||
BIN
backend/app/schemas/__pycache__/__init__.cpython-310.pyc
Normal file
BIN
backend/app/schemas/__pycache__/__init__.cpython-310.pyc
Normal file
Binary file not shown.
BIN
backend/app/schemas/__pycache__/__init__.cpython-311.pyc
Normal file
BIN
backend/app/schemas/__pycache__/__init__.cpython-311.pyc
Normal file
Binary file not shown.
BIN
backend/app/schemas/__pycache__/__init__.cpython-312.pyc
Normal file
BIN
backend/app/schemas/__pycache__/__init__.cpython-312.pyc
Normal file
Binary file not shown.
BIN
backend/app/schemas/__pycache__/order.cpython-310.pyc
Normal file
BIN
backend/app/schemas/__pycache__/order.cpython-310.pyc
Normal file
Binary file not shown.
BIN
backend/app/schemas/__pycache__/order.cpython-311.pyc
Normal file
BIN
backend/app/schemas/__pycache__/order.cpython-311.pyc
Normal file
Binary file not shown.
BIN
backend/app/schemas/__pycache__/order.cpython-312.pyc
Normal file
BIN
backend/app/schemas/__pycache__/order.cpython-312.pyc
Normal file
Binary file not shown.
BIN
backend/app/schemas/__pycache__/user.cpython-310.pyc
Normal file
BIN
backend/app/schemas/__pycache__/user.cpython-310.pyc
Normal file
Binary file not shown.
BIN
backend/app/schemas/__pycache__/user.cpython-311.pyc
Normal file
BIN
backend/app/schemas/__pycache__/user.cpython-311.pyc
Normal file
Binary file not shown.
BIN
backend/app/schemas/__pycache__/user.cpython-312.pyc
Normal file
BIN
backend/app/schemas/__pycache__/user.cpython-312.pyc
Normal file
Binary file not shown.
BIN
backend/app/schemas/__pycache__/work.cpython-310.pyc
Normal file
BIN
backend/app/schemas/__pycache__/work.cpython-310.pyc
Normal file
Binary file not shown.
BIN
backend/app/schemas/__pycache__/work.cpython-311.pyc
Normal file
BIN
backend/app/schemas/__pycache__/work.cpython-311.pyc
Normal file
Binary file not shown.
BIN
backend/app/schemas/__pycache__/work.cpython-312.pyc
Normal file
BIN
backend/app/schemas/__pycache__/work.cpython-312.pyc
Normal file
Binary file not shown.
30
backend/app/schemas/order.py
Normal file
30
backend/app/schemas/order.py
Normal file
@@ -0,0 +1,30 @@
|
||||
from pydantic import BaseModel
|
||||
from typing import Optional
|
||||
from datetime import datetime
|
||||
|
||||
# 创建订单
|
||||
class OrderCreate(BaseModel):
|
||||
work_id: int
|
||||
payment_method: str = "balance" # balance, alipay, wechat
|
||||
|
||||
# 订单响应
|
||||
class OrderResponse(BaseModel):
|
||||
id: int
|
||||
order_no: str
|
||||
user_id: int
|
||||
work_id: int
|
||||
amount: float
|
||||
payment_method: str
|
||||
status: str
|
||||
paid_at: Optional[datetime]
|
||||
created_at: datetime
|
||||
|
||||
class Config:
|
||||
from_attributes = True
|
||||
|
||||
# 支付响应
|
||||
class PaymentResponse(BaseModel):
|
||||
success: bool
|
||||
message: str
|
||||
order_no: str
|
||||
download_url: Optional[str] = None
|
||||
62
backend/app/schemas/user.py
Normal file
62
backend/app/schemas/user.py
Normal file
@@ -0,0 +1,62 @@
|
||||
from pydantic import BaseModel, validator
|
||||
from typing import Optional
|
||||
from datetime import datetime
|
||||
import re
|
||||
|
||||
# 用户注册
|
||||
class UserRegister(BaseModel):
|
||||
phone: str # 手机号必填,作为唯一标识
|
||||
password: str
|
||||
nickname: Optional[str] = None
|
||||
|
||||
@validator('phone')
|
||||
def validate_phone(cls, v):
|
||||
"""验证手机号格式(11位数字)"""
|
||||
if not v:
|
||||
raise ValueError('手机号不能为空')
|
||||
if not re.match(r'^1[3-9]\d{9}$', v):
|
||||
raise ValueError('手机号格式错误,请输入11位有效手机号')
|
||||
return v
|
||||
|
||||
@validator('password')
|
||||
def validate_password(cls, v):
|
||||
"""验证密码"""
|
||||
if not v:
|
||||
raise ValueError('密码不能为空')
|
||||
if len(v) < 6:
|
||||
raise ValueError('密码长度不能少于6位')
|
||||
if len(v) > 72:
|
||||
raise ValueError('密码长度不能超过72位')
|
||||
return v
|
||||
|
||||
# 用户登录
|
||||
class UserLogin(BaseModel):
|
||||
phone: str # 手机号登录
|
||||
password: str
|
||||
|
||||
@validator('phone')
|
||||
def validate_phone(cls, v):
|
||||
"""验证手机号格式(11位数字)"""
|
||||
if not v:
|
||||
raise ValueError('手机号不能为空')
|
||||
if not re.match(r'^1[3-9]\d{9}$', v):
|
||||
raise ValueError('手机号格式错误,请输入11位有效手机号')
|
||||
return v
|
||||
|
||||
# 用户响应
|
||||
class UserResponse(BaseModel):
|
||||
id: int
|
||||
phone: str
|
||||
nickname: Optional[str]
|
||||
avatar: Optional[str]
|
||||
balance: float
|
||||
created_at: datetime
|
||||
|
||||
class Config:
|
||||
from_attributes = True
|
||||
|
||||
# Token 响应
|
||||
class Token(BaseModel):
|
||||
access_token: str
|
||||
token_type: str = "bearer"
|
||||
user: UserResponse
|
||||
50
backend/app/schemas/work.py
Normal file
50
backend/app/schemas/work.py
Normal file
@@ -0,0 +1,50 @@
|
||||
from pydantic import BaseModel
|
||||
from typing import Optional, List
|
||||
from datetime import datetime
|
||||
|
||||
# 作品创建
|
||||
class WorkCreate(BaseModel):
|
||||
title: str
|
||||
category: str
|
||||
designer: str
|
||||
level: int = 1
|
||||
level_text: str = "设计爱好者"
|
||||
price: float # 下载价格
|
||||
description: Optional[str] = None
|
||||
tags: Optional[str] = None
|
||||
|
||||
# 作品更新
|
||||
class WorkUpdate(BaseModel):
|
||||
title: Optional[str] = None
|
||||
price: Optional[float] = None
|
||||
description: Optional[str] = None
|
||||
|
||||
# 作品响应
|
||||
class WorkResponse(BaseModel):
|
||||
id: int
|
||||
title: str
|
||||
category: str
|
||||
designer: str
|
||||
level: int
|
||||
level_text: str
|
||||
|
||||
thumbnail_image: Optional[str]
|
||||
watermarked_image: Optional[str]
|
||||
|
||||
price: float
|
||||
views: int
|
||||
downloads: int
|
||||
collects: int
|
||||
|
||||
description: Optional[str]
|
||||
tags: Optional[str]
|
||||
|
||||
created_at: datetime
|
||||
|
||||
class Config:
|
||||
from_attributes = True
|
||||
|
||||
# 作品列表响应
|
||||
class WorkListResponse(BaseModel):
|
||||
total: int
|
||||
items: List[WorkResponse]
|
||||
Reference in New Issue
Block a user