feat(product): 新增产品接口

This commit is contained in:
xingc
2025-05-06 15:26:40 +08:00
parent 3fcc7a1608
commit 2239418c88
8 changed files with 73 additions and 4 deletions

View File

@@ -5,7 +5,6 @@
# @Author : xingc
# @Desc :
import logging
import xml
from xml.parsers.expat import ExpatError
import xmltodict

View 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 :

View 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
}

View 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

View File

@@ -8,6 +8,7 @@ from .auth.routes import auth_router, test_auth_router
from .card.routes import card_router
from .chat.routes import chat_router
from .pay.routes import pay_router
from .product.routes import product_router
from .file.routes import file_router
from .user.routes import user_router
@@ -17,6 +18,7 @@ routers = [
card_router,
chat_router,
pay_router,
product_router,
file_router,
user_router
]