feat(product): 新增产品接口
This commit is contained in:
@@ -50,7 +50,7 @@ def upgrade() -> None:
|
|||||||
sa.Column('name', sa.String(length=20), nullable=False, comment='产品名'),
|
sa.Column('name', sa.String(length=20), nullable=False, comment='产品名'),
|
||||||
sa.Column('category', sa.Enum('VIP', 'POINTS', name='productcategory', inherit_schema=True), nullable=False, comment='商品分类, vip-会员服务 points-积分服务'),
|
sa.Column('category', sa.Enum('VIP', 'POINTS', name='productcategory', inherit_schema=True), nullable=False, comment='商品分类, vip-会员服务 points-积分服务'),
|
||||||
sa.Column('price', sa.Integer(), nullable=False, comment='价格,不带小数点 单位为分'),
|
sa.Column('price', sa.Integer(), nullable=False, comment='价格,不带小数点 单位为分'),
|
||||||
sa.Column('action', sa.String(length=10), nullable=False, comment='付款后的动作,会员续期:vip_renewal 积分:recharge_points'),
|
sa.Column('action', sa.String(length=30), nullable=False, comment='付款后的动作,会员续期:vip_renewal 积分:recharge_points'),
|
||||||
sa.Column('number', sa.Integer(), nullable=False, comment='执行动作的增量值'),
|
sa.Column('number', sa.Integer(), nullable=False, comment='执行动作的增量值'),
|
||||||
sa.Column('description', sa.Text(), nullable=True, comment='商品描述'),
|
sa.Column('description', sa.Text(), nullable=True, comment='商品描述'),
|
||||||
sa.Column('id', sa.Integer(), autoincrement=True, nullable=False, comment='自增id'),
|
sa.Column('id', sa.Integer(), autoincrement=True, nullable=False, comment='自增id'),
|
||||||
|
|||||||
@@ -79,7 +79,7 @@ class CRUD:
|
|||||||
|
|
||||||
result = await self.session.execute(
|
result = await self.session.execute(
|
||||||
select(model) if filters is None else select(model).filter(
|
select(model) if filters is None else select(model).filter(
|
||||||
*self.build_filter_conditions(filters, model)).order_by(desc(model.insert_time))
|
*self.build_filter_conditions(filters, model)).order_by(desc(model.created_at))
|
||||||
)
|
)
|
||||||
records = result.scalars().all()
|
records = result.scalars().all()
|
||||||
return records
|
return records
|
||||||
|
|||||||
@@ -220,7 +220,7 @@ class Product(BaseModel, DateModel):
|
|||||||
Enum(base_schema.ProductCategory, inherit_schema=True), comment='商品分类, vip-会员服务 points-积分服务'
|
Enum(base_schema.ProductCategory, inherit_schema=True), comment='商品分类, vip-会员服务 points-积分服务'
|
||||||
)
|
)
|
||||||
price: Mapped[int] = mapped_column(Integer, comment='价格,不带小数点 单位为分')
|
price: Mapped[int] = mapped_column(Integer, comment='价格,不带小数点 单位为分')
|
||||||
action: Mapped[str] = mapped_column(String(10), comment='付款后的动作,会员续期:vip_renewal 积分:recharge_points')
|
action: Mapped[str] = mapped_column(String(30), comment='付款后的动作,会员续期:vip_renewal 积分:recharge_points')
|
||||||
number: Mapped[int] = mapped_column(Integer, comment='执行动作的增量值')
|
number: Mapped[int] = mapped_column(Integer, comment='执行动作的增量值')
|
||||||
description: Mapped[str] = mapped_column(Text, nullable=True, comment='商品描述')
|
description: Mapped[str] = mapped_column(Text, nullable=True, comment='商品描述')
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,6 @@
|
|||||||
# @Author : xingc
|
# @Author : xingc
|
||||||
# @Desc :
|
# @Desc :
|
||||||
import logging
|
import logging
|
||||||
import xml
|
|
||||||
from xml.parsers.expat import ExpatError
|
from xml.parsers.expat import ExpatError
|
||||||
|
|
||||||
import xmltodict
|
import xmltodict
|
||||||
|
|||||||
7
core/routers/product/__init__.py
Normal file
7
core/routers/product/__init__.py
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
# @Project : X25020501_card_book
|
||||||
|
# @File : __init__.py.py
|
||||||
|
# @Date : 2025/5/6 14:27
|
||||||
|
# @Software : PyCharm
|
||||||
|
# @Author : xingc
|
||||||
|
# @Desc :
|
||||||
43
core/routers/product/routes.py
Normal file
43
core/routers/product/routes.py
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
# @Project : X25020501_card_book
|
||||||
|
# @File : routes.py
|
||||||
|
# @Date : 2025/5/6 14:29
|
||||||
|
# @Software : PyCharm
|
||||||
|
# @Author : xingc
|
||||||
|
# @Desc :
|
||||||
|
import logging
|
||||||
|
from typing import List
|
||||||
|
|
||||||
|
from fastapi import APIRouter, Depends
|
||||||
|
from sqlalchemy.ext.asyncio import AsyncSession
|
||||||
|
|
||||||
|
from core.base import schema as base_schema
|
||||||
|
from core.db.crud import CRUD
|
||||||
|
from core.db.engine import get_async_session
|
||||||
|
from core.db.models import Product
|
||||||
|
from core.routers.auth.schema import LoginUser
|
||||||
|
from core.routers.auth.services import get_current_user_form_http
|
||||||
|
|
||||||
|
from . import schema
|
||||||
|
|
||||||
|
logger = logging.getLogger(__name__)
|
||||||
|
product_router = APIRouter(prefix='/product', tags=['产品模块'])
|
||||||
|
|
||||||
|
|
||||||
|
@product_router.get(
|
||||||
|
'/all',
|
||||||
|
summary='获取分类产品',
|
||||||
|
response_model=base_schema.BaseResponse[
|
||||||
|
List[schema.ProductOut]
|
||||||
|
]
|
||||||
|
)
|
||||||
|
async def get_products(
|
||||||
|
category: base_schema.ProductCategory,
|
||||||
|
login_user: LoginUser = Depends(get_current_user_form_http),
|
||||||
|
db_session: AsyncSession = Depends(get_async_session)
|
||||||
|
):
|
||||||
|
db_crud = CRUD(db_session, Product)
|
||||||
|
products = await db_crud.get_all(filters={'category': category})
|
||||||
|
return {
|
||||||
|
'data': products
|
||||||
|
}
|
||||||
18
core/routers/product/schema.py
Normal file
18
core/routers/product/schema.py
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
# @Project : X25020501_card_book
|
||||||
|
# @File : schema.py
|
||||||
|
# @Date : 2025/5/6 14:31
|
||||||
|
# @Software : PyCharm
|
||||||
|
# @Author : xingc
|
||||||
|
# @Desc :
|
||||||
|
from pydantic import BaseModel
|
||||||
|
|
||||||
|
from core.base.schema import ProductCategory
|
||||||
|
|
||||||
|
|
||||||
|
class ProductOut(BaseModel):
|
||||||
|
name: str
|
||||||
|
category: ProductCategory
|
||||||
|
price: int
|
||||||
|
number: int
|
||||||
|
description: str | None
|
||||||
@@ -8,6 +8,7 @@ from .auth.routes import auth_router, test_auth_router
|
|||||||
from .card.routes import card_router
|
from .card.routes import card_router
|
||||||
from .chat.routes import chat_router
|
from .chat.routes import chat_router
|
||||||
from .pay.routes import pay_router
|
from .pay.routes import pay_router
|
||||||
|
from .product.routes import product_router
|
||||||
from .file.routes import file_router
|
from .file.routes import file_router
|
||||||
from .user.routes import user_router
|
from .user.routes import user_router
|
||||||
|
|
||||||
@@ -17,6 +18,7 @@ routers = [
|
|||||||
card_router,
|
card_router,
|
||||||
chat_router,
|
chat_router,
|
||||||
pay_router,
|
pay_router,
|
||||||
|
product_router,
|
||||||
file_router,
|
file_router,
|
||||||
user_router
|
user_router
|
||||||
]
|
]
|
||||||
|
|||||||
Reference in New Issue
Block a user