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:
@@ -426,7 +426,7 @@ func TestProfileServiceImpl_Create(t *testing.T) {
|
||||
Email: "test@example.com",
|
||||
Status: 1,
|
||||
}
|
||||
userRepo.Create(testUser)
|
||||
_ = userRepo.Create(context.Background(), testUser)
|
||||
|
||||
cacheManager := NewMockCacheManager()
|
||||
profileService := NewProfileService(profileRepo, userRepo, cacheManager, logger)
|
||||
@@ -459,7 +459,7 @@ func TestProfileServiceImpl_Create(t *testing.T) {
|
||||
wantErr: true,
|
||||
errMsg: "角色名已被使用",
|
||||
setupMocks: func() {
|
||||
profileRepo.Create(&model.Profile{
|
||||
_ = profileRepo.Create(context.Background(), &model.Profile{
|
||||
UUID: "existing-uuid",
|
||||
UserID: 2,
|
||||
Name: "ExistingProfile",
|
||||
@@ -516,7 +516,7 @@ func TestProfileServiceImpl_GetByUUID(t *testing.T) {
|
||||
UserID: 1,
|
||||
Name: "TestProfile",
|
||||
}
|
||||
profileRepo.Create(testProfile)
|
||||
_ = profileRepo.Create(context.Background(), testProfile)
|
||||
|
||||
cacheManager := NewMockCacheManager()
|
||||
profileService := NewProfileService(profileRepo, userRepo, cacheManager, logger)
|
||||
@@ -575,7 +575,7 @@ func TestProfileServiceImpl_Delete(t *testing.T) {
|
||||
UserID: 1,
|
||||
Name: "DeleteTestProfile",
|
||||
}
|
||||
profileRepo.Create(testProfile)
|
||||
_ = profileRepo.Create(context.Background(), testProfile)
|
||||
|
||||
cacheManager := NewMockCacheManager()
|
||||
profileService := NewProfileService(profileRepo, userRepo, cacheManager, logger)
|
||||
@@ -625,9 +625,9 @@ func TestProfileServiceImpl_GetByUserID(t *testing.T) {
|
||||
logger := zap.NewNop()
|
||||
|
||||
// 为用户 1 和 2 预置不同档案
|
||||
profileRepo.Create(&model.Profile{UUID: "p1", UserID: 1, Name: "P1"})
|
||||
profileRepo.Create(&model.Profile{UUID: "p2", UserID: 1, Name: "P2"})
|
||||
profileRepo.Create(&model.Profile{UUID: "p3", UserID: 2, Name: "P3"})
|
||||
_ = profileRepo.Create(context.Background(), &model.Profile{UUID: "p1", UserID: 1, Name: "P1"})
|
||||
_ = profileRepo.Create(context.Background(), &model.Profile{UUID: "p2", UserID: 1, Name: "P2"})
|
||||
_ = profileRepo.Create(context.Background(), &model.Profile{UUID: "p3", UserID: 2, Name: "P3"})
|
||||
|
||||
cacheManager := NewMockCacheManager()
|
||||
svc := NewProfileService(profileRepo, userRepo, cacheManager, logger)
|
||||
@@ -653,7 +653,7 @@ func TestProfileServiceImpl_Update_And_SetActive(t *testing.T) {
|
||||
UserID: 1,
|
||||
Name: "OldName",
|
||||
}
|
||||
profileRepo.Create(profile)
|
||||
_ = profileRepo.Create(context.Background(), profile)
|
||||
|
||||
cacheManager := NewMockCacheManager()
|
||||
svc := NewProfileService(profileRepo, userRepo, cacheManager, logger)
|
||||
@@ -678,7 +678,7 @@ func TestProfileServiceImpl_Update_And_SetActive(t *testing.T) {
|
||||
}
|
||||
|
||||
// 名称重复
|
||||
profileRepo.Create(&model.Profile{
|
||||
_ = profileRepo.Create(context.Background(), &model.Profile{
|
||||
UUID: "u2",
|
||||
UserID: 2,
|
||||
Name: "Duplicate",
|
||||
@@ -705,8 +705,8 @@ func TestProfileServiceImpl_CheckLimit_And_GetByNames(t *testing.T) {
|
||||
logger := zap.NewNop()
|
||||
|
||||
// 为用户 1 预置 2 个档案
|
||||
profileRepo.Create(&model.Profile{UUID: "a", UserID: 1, Name: "A"})
|
||||
profileRepo.Create(&model.Profile{UUID: "b", UserID: 1, Name: "B"})
|
||||
_ = profileRepo.Create(context.Background(), &model.Profile{UUID: "a", UserID: 1, Name: "A"})
|
||||
_ = profileRepo.Create(context.Background(), &model.Profile{UUID: "b", UserID: 1, Name: "B"})
|
||||
|
||||
cacheManager := NewMockCacheManager()
|
||||
svc := NewProfileService(profileRepo, userRepo, cacheManager, logger)
|
||||
|
||||
Reference in New Issue
Block a user