Repo options

This commit is contained in:
Eden Kirin
2024-06-25 01:19:40 +02:00
parent c2bcbea5d2
commit 4615d55309
8 changed files with 112 additions and 37 deletions

View File

@ -3,7 +3,6 @@ package repository
import (
"repo-pattern/app/repository/smartfilter"
"gorm.io/gorm"
"gorm.io/gorm/schema"
)
@ -14,11 +13,11 @@ type ListOptions struct {
}
type ListMethod[T schema.Tabler] struct {
DbConn *gorm.DB
repo *RepoBase[T]
}
func (m *ListMethod[T]) Init(dbConn *gorm.DB) {
m.DbConn = dbConn
func (m *ListMethod[T]) Init(repo *RepoBase[T]) {
m.repo = repo
}
func (m ListMethod[T]) List(filter interface{}, options *ListOptions) (*[]T, error) {
@ -27,7 +26,7 @@ func (m ListMethod[T]) List(filter interface{}, options *ListOptions) (*[]T, err
models []T
)
query, err := smartfilter.ToQuery(model, filter, m.DbConn)
query, err := smartfilter.ToQuery(model, filter, m.repo.dbConn)
if err != nil {
return nil, err
}