2025-11-28 23:30:49 +08:00
|
|
|
package repository
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"carrotskin/internal/model"
|
2025-12-03 15:27:12 +08:00
|
|
|
"context"
|
2025-12-02 22:52:33 +08:00
|
|
|
|
|
|
|
|
"gorm.io/gorm"
|
2025-11-28 23:30:49 +08:00
|
|
|
)
|
|
|
|
|
|
2025-12-02 22:52:33 +08:00
|
|
|
// yggdrasilRepository YggdrasilRepository的实现
|
|
|
|
|
type yggdrasilRepository struct {
|
|
|
|
|
db *gorm.DB
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// NewYggdrasilRepository 创建YggdrasilRepository实例
|
|
|
|
|
func NewYggdrasilRepository(db *gorm.DB) YggdrasilRepository {
|
|
|
|
|
return &yggdrasilRepository{db: db}
|
|
|
|
|
}
|
|
|
|
|
|
2025-12-03 15:27:12 +08:00
|
|
|
func (r *yggdrasilRepository) GetPasswordByID(ctx context.Context, id int64) (string, error) {
|
2025-11-28 23:30:49 +08:00
|
|
|
var yggdrasil model.Yggdrasil
|
2025-12-03 15:27:12 +08:00
|
|
|
err := r.db.WithContext(ctx).Select("password").Where("id = ?", id).First(&yggdrasil).Error
|
2025-11-28 23:30:49 +08:00
|
|
|
if err != nil {
|
|
|
|
|
return "", err
|
|
|
|
|
}
|
|
|
|
|
return yggdrasil.Password, nil
|
|
|
|
|
}
|
2025-11-30 18:56:56 +08:00
|
|
|
|
2025-12-03 15:27:12 +08:00
|
|
|
func (r *yggdrasilRepository) ResetPassword(ctx context.Context, id int64, password string) error {
|
|
|
|
|
return r.db.WithContext(ctx).Model(&model.Yggdrasil{}).Where("id = ?", id).Update("password", password).Error
|
2025-12-02 22:52:33 +08:00
|
|
|
}
|
2025-12-07 10:10:28 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|