Save method

This commit is contained in:
Eden Kirin
2024-06-26 01:55:33 +02:00
parent 3dc8d0d79f
commit bdc978aec1
6 changed files with 126 additions and 18 deletions

View File

@ -21,11 +21,11 @@ type RepoBase[T schema.Tabler] struct {
GetMethod[T]
ExistsMethod[T]
CountMethod[T]
methods []MethodInitInterface[T]
SaveMethod[T]
}
func (repo *RepoBase[T]) InitMethods() {
for _, method := range repo.methods {
func (repo *RepoBase[T]) InitMethods(methods []MethodInitInterface[T]) {
for _, method := range methods {
method.Init(repo)
}
}
@ -42,11 +42,12 @@ func (m *RepoBase[T]) Init(dbConn *gorm.DB, options *RepoOptions) {
}
}
m.methods = []MethodInitInterface[T]{
methods := []MethodInitInterface[T]{
&m.ListMethod,
&m.GetMethod,
&m.ExistsMethod,
&m.CountMethod,
&m.SaveMethod,
}
m.InitMethods()
m.InitMethods(methods)
}