29 lines
649 B
Go
29 lines
649 B
Go
package logic
|
|
|
|
import (
|
|
"github.com/gin-gonic/gin"
|
|
"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{}
|
|
}
|
|
|
|
func (l *LibraryLogic) ListLibrary(ctx *gin.Context) ([]*ent.Library, error) {
|
|
return client.Library.Query().Where(library.UserID(GetUserId(ctx))).All(ctx)
|
|
}
|
|
|
|
func (l *LibraryLogic) CreateLibrary(ctx *gin.Context, name string) (*ent.Library, error) {
|
|
return client.Library.Create().
|
|
SetName(name).
|
|
SetUserID(GetUserId(ctx)).
|
|
Save(ctx)
|
|
}
|