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:
lan
2025-12-03 15:27:12 +08:00
parent 4824a997dd
commit 0bcd9336c4
32 changed files with 833 additions and 497 deletions

View File

@@ -38,7 +38,7 @@ func NewYggdrasilAuthService(
}
func (s *yggdrasilAuthService) GetUserIDByEmail(ctx context.Context, email string) (int64, error) {
user, err := s.userRepo.FindByEmail(email)
user, err := s.userRepo.FindByEmail(ctx, email)
if err != nil {
return 0, apperrors.ErrUserNotFound
}
@@ -46,7 +46,7 @@ func (s *yggdrasilAuthService) GetUserIDByEmail(ctx context.Context, email strin
}
func (s *yggdrasilAuthService) VerifyPassword(ctx context.Context, password string, userID int64) error {
passwordStore, err := s.yggdrasilRepo.GetPasswordByID(userID)
passwordStore, err := s.yggdrasilRepo.GetPasswordByID(ctx, userID)
if err != nil {
return apperrors.ErrPasswordNotSet
}
@@ -68,7 +68,7 @@ func (s *yggdrasilAuthService) ResetYggdrasilPassword(ctx context.Context, userI
}
// 检查Yggdrasil记录是否存在
_, err = s.yggdrasilRepo.GetPasswordByID(userID)
_, err = s.yggdrasilRepo.GetPasswordByID(ctx, userID)
if err != nil {
// 如果不存在,创建新记录
yggdrasil := model.Yggdrasil{
@@ -82,7 +82,7 @@ func (s *yggdrasilAuthService) ResetYggdrasilPassword(ctx context.Context, userI
}
// 如果存在,更新密码(存储加密后的密码)
if err := s.yggdrasilRepo.ResetPassword(userID, hashedPassword); err != nil {
if err := s.yggdrasilRepo.ResetPassword(ctx, userID, hashedPassword); err != nil {
return "", fmt.Errorf("重置Yggdrasil密码失败: %w", err)
}