refactor: Update service and repository methods to use context
- Refactored multiple service and repository methods to accept context as a parameter, enhancing consistency and enabling better control over request lifecycles. - Updated handlers to utilize context in method calls, improving error handling and performance. - Cleaned up Dockerfile by removing unnecessary whitespace.
This commit is contained in:
@@ -2,6 +2,7 @@ package repository
|
||||
|
||||
import (
|
||||
"carrotskin/internal/model"
|
||||
"context"
|
||||
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
@@ -16,15 +17,15 @@ func NewYggdrasilRepository(db *gorm.DB) YggdrasilRepository {
|
||||
return &yggdrasilRepository{db: db}
|
||||
}
|
||||
|
||||
func (r *yggdrasilRepository) GetPasswordByID(id int64) (string, error) {
|
||||
func (r *yggdrasilRepository) GetPasswordByID(ctx context.Context, id int64) (string, error) {
|
||||
var yggdrasil model.Yggdrasil
|
||||
err := r.db.Select("password").Where("id = ?", id).First(&yggdrasil).Error
|
||||
err := r.db.WithContext(ctx).Select("password").Where("id = ?", id).First(&yggdrasil).Error
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return yggdrasil.Password, nil
|
||||
}
|
||||
|
||||
func (r *yggdrasilRepository) ResetPassword(id int64, password string) error {
|
||||
return r.db.Model(&model.Yggdrasil{}).Where("id = ?", id).Update("password", password).Error
|
||||
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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user