rag/internal/logic/library.go

29 lines
638 B
Go
Raw Normal View History

package logic
import (
2024-07-15 18:05:02 +00:00
"context"
"leafdev.top/leaf/rag/ent"
"leafdev.top/leaf/rag/ent/library"
"leafdev.top/leaf/rag/internal/providers"
)
type LibraryLogic struct {
}
var client = providers.MustGet[ent.Client]()
func NewLibraryLogic() *LibraryLogic {
return &LibraryLogic{}
}
2024-07-15 18:05:02 +00:00
func (l *LibraryLogic) ListLibrary(ctx context.Context) ([]*ent.Library, error) {
return client.Library.Query().Where(library.UserID(GetUserId(ctx))).All(ctx)
}
2024-07-15 18:05:02 +00:00
func (l *LibraryLogic) CreateLibrary(ctx context.Context, name string) (*ent.Library, error) {
return client.Library.Create().
SetName(name).
SetUserID(GetUserId(ctx)).
Save(ctx)
}