30 lines
698 B
Go
30 lines
698 B
Go
package repo
|
|
|
|
import (
|
|
"ai_scheduler/internal/data/impl"
|
|
"context"
|
|
"errors"
|
|
)
|
|
|
|
// SessionAdapter 适配 impl.SessionImpl 到 SessionRepo 接口
|
|
type SessionAdapter struct {
|
|
impl *impl.SessionImpl
|
|
}
|
|
|
|
func NewSessionAdapter(impl *impl.SessionImpl) *SessionAdapter {
|
|
return &SessionAdapter{impl: impl}
|
|
}
|
|
|
|
func (s *SessionAdapter) GetUserName(ctx context.Context, sessionID string) (string, error) {
|
|
// 复用 SessionImpl 的查询能力
|
|
// 这里假设 sessionID 是唯一的,直接用 FindOne
|
|
session, has, err := s.impl.FindOne(s.impl.WithSessionId(sessionID))
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
if !has {
|
|
return "", errors.New("session not found")
|
|
}
|
|
return session.UserName, nil
|
|
}
|