27 lines
594 B
Go
27 lines
594 B
Go
package ai
|
|
|
|
import (
|
|
"errors"
|
|
"strings"
|
|
|
|
"gorm.io/gorm"
|
|
"senlinai-agent/backend/internal/domain"
|
|
)
|
|
|
|
type SessionService struct {
|
|
db *gorm.DB
|
|
}
|
|
|
|
func NewSessionService(database *gorm.DB) *SessionService {
|
|
return &SessionService{db: database}
|
|
}
|
|
|
|
func (s *SessionService) Create(projectID uint, userID uint, title string) (*domain.AISession, error) {
|
|
title = strings.TrimSpace(title)
|
|
if title == "" {
|
|
return nil, errors.New("session title is required")
|
|
}
|
|
session := &domain.AISession{ProjectID: projectID, CreatedBy: userID, Title: title}
|
|
return session, s.db.Create(session).Error
|
|
}
|