- Add end_user_controller with unauthenticated endpoint for creating end users - Implement get_or_create_end_user logic to handle duplicate end users by other_id - Register end_user_controller router in main controller initialization - Add list_memory_configs endpoint to retrieve all workspace memory configurations - Update MemoryWriteRequest and MemoryReadRequest to make config_id required field - Refactor memory API endpoints to parse request body directly instead of using Body parameter - Add CreateEndUserRequest and CreateEndUserResponse schemas for end user creation - Add ListConfigsResponse schema for configs listing endpoint - Remove unused config_id and llm_model_id parameters from Neo4j write operation - Update .gitignore to exclude redbear-mem-metrics and pitch-deck directories
49 lines
1.4 KiB
Python
49 lines
1.4 KiB
Python
"""End User 管理接口 - 无需认证"""
|
|
|
|
from app.core.logging_config import get_business_logger
|
|
from app.core.response_utils import success
|
|
from app.db import get_db
|
|
from app.repositories.end_user_repository import EndUserRepository
|
|
from app.schemas.memory_api_schema import (
|
|
CreateEndUserRequest,
|
|
CreateEndUserResponse,
|
|
)
|
|
from fastapi import APIRouter, Depends
|
|
from sqlalchemy.orm import Session
|
|
|
|
router = APIRouter(prefix="/end_users", tags=["End Users"])
|
|
logger = get_business_logger()
|
|
|
|
|
|
@router.post("")
|
|
async def create_end_user(
|
|
data: CreateEndUserRequest,
|
|
db: Session = Depends(get_db),
|
|
):
|
|
"""
|
|
Create an end user.
|
|
|
|
Creates a new end user for the given workspace.
|
|
If an end user with the same other_id already exists in the workspace,
|
|
returns the existing one.
|
|
"""
|
|
logger.info(f"Create end user request - other_id: {data.other_id}, workspace_id: {data.workspace_id}")
|
|
|
|
end_user_repo = EndUserRepository(db)
|
|
end_user = end_user_repo.get_or_create_end_user(
|
|
app_id=None,
|
|
workspace_id=data.workspace_id,
|
|
other_id=data.other_id,
|
|
)
|
|
|
|
logger.info(f"End user ready: {end_user.id}")
|
|
|
|
result = {
|
|
"id": str(end_user.id),
|
|
"other_id": end_user.other_id or "",
|
|
"other_name": end_user.other_name or "",
|
|
"workspace_id": str(end_user.workspace_id),
|
|
}
|
|
|
|
return success(data=CreateEndUserResponse(**result).model_dump(), msg="End user created successfully")
|