29 lines
981 B
Python
29 lines
981 B
Python
from sqlalchemy import Column, Integer, String, DateTime, ForeignKey, DECIMAL
|
|
from sqlalchemy.sql import func
|
|
from pydantic import BaseModel, Field
|
|
from typing import Optional
|
|
from datetime import datetime
|
|
from .database import Base
|
|
|
|
class PointRecordDB(Base):
|
|
__tablename__ = "point_records"
|
|
|
|
id = Column(Integer, primary_key=True, autoincrement=True)
|
|
user_id = Column(Integer, ForeignKey("users.userid"), nullable=False)
|
|
points = Column(DECIMAL(10,1), nullable=False)
|
|
description = Column(String(200), nullable=False)
|
|
create_time = Column(DateTime(timezone=True), server_default=func.now())
|
|
|
|
class PointRecordCreate(BaseModel):
|
|
points: float = Field(..., description="积分变动值,可为正或负")
|
|
description: str = Field(..., min_length=1, max_length=200)
|
|
|
|
class PointRecordInfo(BaseModel):
|
|
id: int
|
|
user_id: int
|
|
points: float
|
|
description: str
|
|
create_time: datetime
|
|
|
|
class Config:
|
|
from_attributes = True |