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:
@@ -491,7 +491,7 @@ func TestTextureServiceImpl_Create(t *testing.T) {
|
||||
Email: "test@example.com",
|
||||
Status: 1,
|
||||
}
|
||||
userRepo.Create(testUser)
|
||||
_ = userRepo.Create(context.Background(), testUser)
|
||||
|
||||
cacheManager := NewMockCacheManager()
|
||||
textureService := NewTextureService(textureRepo, userRepo, cacheManager, logger)
|
||||
@@ -539,7 +539,7 @@ func TestTextureServiceImpl_Create(t *testing.T) {
|
||||
wantErr: true,
|
||||
errContains: "已存在",
|
||||
setupMocks: func() {
|
||||
textureRepo.Create(&model.Texture{
|
||||
_ = textureRepo.Create(context.Background(), &model.Texture{
|
||||
ID: 100,
|
||||
UploaderID: 1,
|
||||
Name: "ExistingTexture",
|
||||
@@ -614,7 +614,7 @@ func TestTextureServiceImpl_GetByID(t *testing.T) {
|
||||
Name: "TestTexture",
|
||||
Hash: "test-hash",
|
||||
}
|
||||
textureRepo.Create(testTexture)
|
||||
_ = textureRepo.Create(context.Background(), testTexture)
|
||||
|
||||
cacheManager := NewMockCacheManager()
|
||||
textureService := NewTextureService(textureRepo, userRepo, cacheManager, logger)
|
||||
@@ -666,7 +666,7 @@ func TestTextureServiceImpl_GetByUserID_And_Search(t *testing.T) {
|
||||
|
||||
// 预置多条 Texture
|
||||
for i := int64(1); i <= 5; i++ {
|
||||
textureRepo.Create(&model.Texture{
|
||||
_ = textureRepo.Create(context.Background(), &model.Texture{
|
||||
ID: i,
|
||||
UploaderID: 1,
|
||||
Name: "T",
|
||||
@@ -711,7 +711,7 @@ func TestTextureServiceImpl_Update_And_Delete(t *testing.T) {
|
||||
Description: "OldDesc",
|
||||
IsPublic: false,
|
||||
}
|
||||
textureRepo.Create(texture)
|
||||
_ = textureRepo.Create(context.Background(), texture)
|
||||
|
||||
cacheManager := NewMockCacheManager()
|
||||
textureService := NewTextureService(textureRepo, userRepo, cacheManager, logger)
|
||||
@@ -755,12 +755,12 @@ func TestTextureServiceImpl_FavoritesAndLimit(t *testing.T) {
|
||||
|
||||
// 预置若干 Texture 与收藏关系
|
||||
for i := int64(1); i <= 3; i++ {
|
||||
textureRepo.Create(&model.Texture{
|
||||
_ = textureRepo.Create(context.Background(), &model.Texture{
|
||||
ID: i,
|
||||
UploaderID: 1,
|
||||
Name: "T",
|
||||
})
|
||||
_ = textureRepo.AddFavorite(1, i)
|
||||
_ = textureRepo.AddFavorite(context.Background(), 1, i)
|
||||
}
|
||||
|
||||
cacheManager := NewMockCacheManager()
|
||||
@@ -796,7 +796,7 @@ func TestTextureServiceImpl_ToggleFavorite(t *testing.T) {
|
||||
|
||||
// 预置用户和Texture
|
||||
testUser := &model.User{ID: 1, Username: "testuser", Status: 1}
|
||||
userRepo.Create(testUser)
|
||||
_ = userRepo.Create(context.Background(), testUser)
|
||||
|
||||
testTexture := &model.Texture{
|
||||
ID: 1,
|
||||
@@ -804,7 +804,7 @@ func TestTextureServiceImpl_ToggleFavorite(t *testing.T) {
|
||||
Name: "TestTexture",
|
||||
Hash: "test-hash",
|
||||
}
|
||||
textureRepo.Create(testTexture)
|
||||
_ = textureRepo.Create(context.Background(), testTexture)
|
||||
|
||||
cacheManager := NewMockCacheManager()
|
||||
textureService := NewTextureService(textureRepo, userRepo, cacheManager, logger)
|
||||
|
||||
Reference in New Issue
Block a user