Cleanup
This commit is contained in:
31
app/repository/method_list.go
Normal file
31
app/repository/method_list.go
Normal file
@ -0,0 +1,31 @@
|
||||
package repository
|
||||
|
||||
import (
|
||||
"repo-pattern/app/repository/smartfilter"
|
||||
|
||||
"gorm.io/gorm"
|
||||
"gorm.io/gorm/schema"
|
||||
)
|
||||
|
||||
type ListMethod[T schema.Tabler] struct {
|
||||
DbConn *gorm.DB
|
||||
}
|
||||
|
||||
func (m *ListMethod[T]) Init(dbConn *gorm.DB) {
|
||||
m.DbConn = dbConn
|
||||
}
|
||||
|
||||
func (m ListMethod[T]) List(filter interface{}) (*[]T, error) {
|
||||
var (
|
||||
model T
|
||||
models []T
|
||||
)
|
||||
|
||||
query, err := smartfilter.ToQuery(model, filter, m.DbConn)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
query.Find(&models)
|
||||
return &models, nil
|
||||
}
|
||||
Reference in New Issue
Block a user