docs(readme): 编写项目README文档,描述功能与架构
- 完整撰写玉宗珠宝设计大师项目README,介绍项目概况及核心功能 - 说明用户认证系统实现及优势,包含JWT鉴权和密码加密细节 - 详细描述品类管理系统,支持多流程类型和多种玉石品类 - 说明设计图生成方案及技术,包含Pillow生成示例及字体支持 - 介绍设计管理功能,支持分页浏览、预览、下载和删除设计 - 个人信息管理模块说明,涵盖昵称、手机号、密码的安全修改 - 绘制业务流程图和关键数据流图,清晰展现系统架构与数据流 - 提供详细API调用链路及参数说明,涵盖用户、品类、设计接口 - 列明技术栈及版本,包含前后端框架、ORM、认证、加密等工具 - 展示目录结构,标明后端与前端项目布局 - 规划本地开发环境与启动步骤,包括数据库初始化及运行命令 - 说明服务器部署流程和Nginx配置方案 - 详细数据库表结构说明及环境变量配置指导 - 汇总常用开发及测试命令,方便开发调试与部署管理
This commit is contained in:
71
backend/app/routers/categories.py
Normal file
71
backend/app/routers/categories.py
Normal file
@@ -0,0 +1,71 @@
|
||||
"""
|
||||
品类相关路由
|
||||
提供品类、子类型、颜色的查询接口
|
||||
"""
|
||||
from fastapi import APIRouter, Depends, HTTPException, status
|
||||
from sqlalchemy.orm import Session
|
||||
from typing import List
|
||||
|
||||
from ..database import get_db
|
||||
from ..models import Category, SubType, Color
|
||||
from ..schemas import CategoryResponse, SubTypeResponse, ColorResponse
|
||||
|
||||
router = APIRouter(prefix="/api/categories", tags=["品类"])
|
||||
|
||||
|
||||
@router.get("", response_model=List[CategoryResponse])
|
||||
def get_categories(db: Session = Depends(get_db)):
|
||||
"""
|
||||
获取所有品类列表
|
||||
按 sort_order 排序,无需认证
|
||||
"""
|
||||
categories = db.query(Category).order_by(Category.sort_order).all()
|
||||
return categories
|
||||
|
||||
|
||||
@router.get("/{category_id}/sub-types", response_model=List[SubTypeResponse])
|
||||
def get_category_sub_types(
|
||||
category_id: int,
|
||||
db: Session = Depends(get_db)
|
||||
):
|
||||
"""
|
||||
获取品类下的子类型
|
||||
无需认证
|
||||
"""
|
||||
# 检查品类是否存在
|
||||
category = db.query(Category).filter(Category.id == category_id).first()
|
||||
if not category:
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_404_NOT_FOUND,
|
||||
detail="品类不存在"
|
||||
)
|
||||
|
||||
sub_types = db.query(SubType).filter(
|
||||
SubType.category_id == category_id
|
||||
).order_by(SubType.sort_order).all()
|
||||
|
||||
return sub_types
|
||||
|
||||
|
||||
@router.get("/{category_id}/colors", response_model=List[ColorResponse])
|
||||
def get_category_colors(
|
||||
category_id: int,
|
||||
db: Session = Depends(get_db)
|
||||
):
|
||||
"""
|
||||
获取品类下的颜色选项
|
||||
无需认证
|
||||
"""
|
||||
# 检查品类是否存在
|
||||
category = db.query(Category).filter(Category.id == category_id).first()
|
||||
if not category:
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_404_NOT_FOUND,
|
||||
detail="品类不存在"
|
||||
)
|
||||
|
||||
colors = db.query(Color).filter(
|
||||
Color.category_id == category_id
|
||||
).order_by(Color.sort_order).all()
|
||||
|
||||
return colors
|
||||
Reference in New Issue
Block a user