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"
)
@ -13,11 +12,11 @@ type GetOptions struct {
}
type GetMethod[T schema.Tabler] struct {
DbConn *gorm.DB
repo *RepoBase[T]
}
func (m *GetMethod[T]) Init(dbConn *gorm.DB) {
m.DbConn = dbConn
func (m *GetMethod[T]) Init(repo *RepoBase[T]) {
m.repo = repo
}
func (m GetMethod[T]) Get(filter interface{}, options *GetOptions) (*T, error) {
@ -25,7 +24,7 @@ func (m GetMethod[T]) Get(filter interface{}, options *GetOptions) (*T, error) {
model T
)
query, err := smartfilter.ToQuery(model, filter, m.DbConn)
query, err := smartfilter.ToQuery(model, filter, m.repo.dbConn)
if err != nil {
return nil, err
}