feat: 初始化孕育无忧全栈项目基础代码结构
完成项目初始搭建,包含后端FastAPI+MongoDB服务、前端React+Vite项目的完整基础结构,添加各类配置文件与依赖清单,涵盖核心业务初始框架。
This commit is contained in:
19
backend/app/utils/helpers.py
Normal file
19
backend/app/utils/helpers.py
Normal file
@@ -0,0 +1,19 @@
|
||||
from typing import Optional
|
||||
|
||||
from beanie import PydanticObjectId
|
||||
from fastapi import HTTPException
|
||||
|
||||
|
||||
def parse_object_id(value: str) -> PydanticObjectId:
|
||||
"""Parse a string to PydanticObjectId, raising 400 on invalid format."""
|
||||
try:
|
||||
return PydanticObjectId(value)
|
||||
except Exception:
|
||||
raise HTTPException(status_code=400, detail="无效的ID格式")
|
||||
|
||||
|
||||
def mask_name(name: Optional[str]) -> str:
|
||||
"""隐私脱敏:姓名"""
|
||||
if not name or len(name) < 2:
|
||||
return name or ""
|
||||
return name[0] + "*" * (len(name) - 1)
|
||||
Reference in New Issue
Block a user