26 lines
883 B
Python
26 lines
883 B
Python
from sqlalchemy import select
|
|
from sqlalchemy.orm import Session
|
|
|
|
from app.models.user import UserLearningProfile
|
|
|
|
|
|
class UserLearningProfileRepository:
|
|
"""学习档案仓储:维护用户训练评价聚合数据。"""
|
|
|
|
def __init__(self, db: Session) -> None:
|
|
self.db = db
|
|
|
|
def get_profile(self, user_id: str, tenant_id: str | None) -> UserLearningProfile | None:
|
|
"""档案读取:按 user_id 和 tenant_id 获取学习档案。"""
|
|
stmt = select(UserLearningProfile).where(
|
|
UserLearningProfile.user_id == user_id,
|
|
UserLearningProfile.tenant_id == tenant_id,
|
|
)
|
|
return self.db.scalar(stmt)
|
|
|
|
def save(self, profile: UserLearningProfile) -> UserLearningProfile:
|
|
"""档案保存:创建或更新用户学习档案。"""
|
|
self.db.add(profile)
|
|
self.db.flush()
|
|
return profile
|