migrate from github

This commit is contained in:
2026-07-15 22:42:31 +08:00
commit 3ad559f05e
262 changed files with 21637 additions and 0 deletions
+45
View File
@@ -0,0 +1,45 @@
package user_repo
import (
"context"
"github.com/XingfenD/yoresee_doc/internal/model"
"github.com/XingfenD/yoresee_doc/pkg/key"
"gorm.io/gorm"
)
type UserUpdateOperation struct {
repo *UserRepository
user *model.User
tx *gorm.DB
}
func (r *UserRepository) Update(user *model.User) *UserUpdateOperation {
return &UserUpdateOperation{
repo: r,
user: user,
}
}
func (op *UserUpdateOperation) WithTx(tx *gorm.DB) *UserUpdateOperation {
op.tx = tx
return op
}
func (op *UserUpdateOperation) Exec() error {
if op.tx != nil {
if err := op.tx.Save(op.user).Error; err != nil {
return err
}
return op.clearQueryCache()
}
if err := op.repo.db.Save(op.user).Error; err != nil {
return err
}
return op.clearQueryCache()
}
func (op *UserUpdateOperation) clearQueryCache() error {
_, _ = op.repo.redis.Incr(context.Background(), key.KeyUserQueryVersion()).Result()
return nil
}