rag/internal/logic/library.go
2024-07-20 23:19:25 +08:00

32 lines
643 B
Go

package logic
import (
"context"
"errors"
"leafdev.top/leaf/rag/ent"
"leafdev.top/leaf/rag/ent/library"
)
type LibraryLogic struct {
}
func NewLibraryLogic() *LibraryLogic {
return &LibraryLogic{}
}
func (l *LibraryLogic) ListLibrary(ctx context.Context) ([]*ent.Library, error) {
return orm.Library.Query().Where(library.UserID(GetUserId(ctx))).All(ctx)
}
func (l *LibraryLogic) CreateLibrary(ctx context.Context, name string) (*ent.Library, error) {
// name 不能为空
if name == "" {
return nil, errors.New("名称不能为空")
}
return orm.Library.Create().
SetName(name).
SetUserID(GetUserId(ctx)).
Save(ctx)
}