Working version

This commit is contained in:
Eden Kirin
2024-06-22 13:34:27 +02:00
parent 104f8b5459
commit 14bc29d7e3
9 changed files with 496 additions and 147 deletions

View File

@ -0,0 +1,29 @@
package repository
import (
"gorm.io/gorm"
"gorm.io/gorm/schema"
)
type MethodInitInterface interface {
Init(dbConn *gorm.DB)
}
type RepoBase[T schema.Tabler] struct {
DbConn int
ListMethod[T]
GetMethod[T]
ExistsMethod[T]
methods []MethodInitInterface
}
func (b *RepoBase[T]) InitMethods(dbConn *gorm.DB) {
for _, method := range b.methods {
method.Init(dbConn)
}
}
func (m *RepoBase[T]) Init(dbConn *gorm.DB) {
m.methods = []MethodInitInterface{&m.ListMethod, &m.GetMethod, &m.ExistsMethod}
m.InitMethods(dbConn)
}