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:
@@ -3,6 +3,7 @@ package service
|
||||
import (
|
||||
"carrotskin/internal/model"
|
||||
"carrotskin/pkg/database"
|
||||
"context"
|
||||
"errors"
|
||||
"time"
|
||||
)
|
||||
@@ -28,7 +29,7 @@ func NewMockUserRepository() *MockUserRepository {
|
||||
}
|
||||
}
|
||||
|
||||
func (m *MockUserRepository) Create(user *model.User) error {
|
||||
func (m *MockUserRepository) Create(ctx context.Context, user *model.User) error {
|
||||
if m.FailCreate {
|
||||
return errors.New("mock create error")
|
||||
}
|
||||
@@ -39,7 +40,7 @@ func (m *MockUserRepository) Create(user *model.User) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *MockUserRepository) FindByID(id int64) (*model.User, error) {
|
||||
func (m *MockUserRepository) FindByID(ctx context.Context, id int64) (*model.User, error) {
|
||||
if m.FailFindByID {
|
||||
return nil, errors.New("mock find error")
|
||||
}
|
||||
@@ -49,7 +50,7 @@ func (m *MockUserRepository) FindByID(id int64) (*model.User, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (m *MockUserRepository) FindByUsername(username string) (*model.User, error) {
|
||||
func (m *MockUserRepository) FindByUsername(ctx context.Context, username string) (*model.User, error) {
|
||||
if m.FailFindByUsername {
|
||||
return nil, errors.New("mock find by username error")
|
||||
}
|
||||
@@ -61,7 +62,7 @@ func (m *MockUserRepository) FindByUsername(username string) (*model.User, error
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (m *MockUserRepository) FindByEmail(email string) (*model.User, error) {
|
||||
func (m *MockUserRepository) FindByEmail(ctx context.Context, email string) (*model.User, error) {
|
||||
if m.FailFindByEmail {
|
||||
return nil, errors.New("mock find by email error")
|
||||
}
|
||||
@@ -73,7 +74,7 @@ func (m *MockUserRepository) FindByEmail(email string) (*model.User, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (m *MockUserRepository) Update(user *model.User) error {
|
||||
func (m *MockUserRepository) Update(ctx context.Context, user *model.User) error {
|
||||
if m.FailUpdate {
|
||||
return errors.New("mock update error")
|
||||
}
|
||||
@@ -81,7 +82,7 @@ func (m *MockUserRepository) Update(user *model.User) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *MockUserRepository) UpdateFields(id int64, fields map[string]interface{}) error {
|
||||
func (m *MockUserRepository) UpdateFields(ctx context.Context, id int64, fields map[string]interface{}) error {
|
||||
if m.FailUpdate {
|
||||
return errors.New("mock update fields error")
|
||||
}
|
||||
@@ -92,23 +93,43 @@ func (m *MockUserRepository) UpdateFields(id int64, fields map[string]interface{
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *MockUserRepository) Delete(id int64) error {
|
||||
func (m *MockUserRepository) Delete(ctx context.Context, id int64) error {
|
||||
delete(m.users, id)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *MockUserRepository) CreateLoginLog(log *model.UserLoginLog) error {
|
||||
func (m *MockUserRepository) CreateLoginLog(ctx context.Context, log *model.UserLoginLog) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *MockUserRepository) CreatePointLog(log *model.UserPointLog) error {
|
||||
func (m *MockUserRepository) CreatePointLog(ctx context.Context, log *model.UserPointLog) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *MockUserRepository) UpdatePoints(userID int64, amount int, changeType, reason string) error {
|
||||
func (m *MockUserRepository) UpdatePoints(ctx context.Context, userID int64, amount int, changeType, reason string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// BatchUpdate 和 BatchDelete 仅用于满足接口,在测试中不做具体操作
|
||||
func (m *MockUserRepository) BatchUpdate(ctx context.Context, ids []int64, fields map[string]interface{}) (int64, error) {
|
||||
return 0, nil
|
||||
}
|
||||
|
||||
func (m *MockUserRepository) BatchDelete(ctx context.Context, ids []int64) (int64, error) {
|
||||
return 0, nil
|
||||
}
|
||||
|
||||
// FindByIDs 批量查询用户
|
||||
func (m *MockUserRepository) FindByIDs(ctx context.Context, ids []int64) ([]*model.User, error) {
|
||||
var result []*model.User
|
||||
for _, id := range ids {
|
||||
if u, ok := m.users[id]; ok {
|
||||
result = append(result, u)
|
||||
}
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
|
||||
// MockProfileRepository 模拟ProfileRepository
|
||||
type MockProfileRepository struct {
|
||||
profiles map[string]*model.Profile
|
||||
@@ -128,7 +149,7 @@ func NewMockProfileRepository() *MockProfileRepository {
|
||||
}
|
||||
}
|
||||
|
||||
func (m *MockProfileRepository) Create(profile *model.Profile) error {
|
||||
func (m *MockProfileRepository) Create(ctx context.Context, profile *model.Profile) error {
|
||||
if m.FailCreate {
|
||||
return errors.New("mock create error")
|
||||
}
|
||||
@@ -137,7 +158,7 @@ func (m *MockProfileRepository) Create(profile *model.Profile) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *MockProfileRepository) FindByUUID(uuid string) (*model.Profile, error) {
|
||||
func (m *MockProfileRepository) FindByUUID(ctx context.Context, uuid string) (*model.Profile, error) {
|
||||
if m.FailFind {
|
||||
return nil, errors.New("mock find error")
|
||||
}
|
||||
@@ -147,7 +168,7 @@ func (m *MockProfileRepository) FindByUUID(uuid string) (*model.Profile, error)
|
||||
return nil, errors.New("profile not found")
|
||||
}
|
||||
|
||||
func (m *MockProfileRepository) FindByName(name string) (*model.Profile, error) {
|
||||
func (m *MockProfileRepository) FindByName(ctx context.Context, name string) (*model.Profile, error) {
|
||||
if m.FailFind {
|
||||
return nil, errors.New("mock find error")
|
||||
}
|
||||
@@ -159,14 +180,14 @@ func (m *MockProfileRepository) FindByName(name string) (*model.Profile, error)
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (m *MockProfileRepository) FindByUserID(userID int64) ([]*model.Profile, error) {
|
||||
func (m *MockProfileRepository) FindByUserID(ctx context.Context, userID int64) ([]*model.Profile, error) {
|
||||
if m.FailFind {
|
||||
return nil, errors.New("mock find error")
|
||||
}
|
||||
return m.userProfiles[userID], nil
|
||||
}
|
||||
|
||||
func (m *MockProfileRepository) Update(profile *model.Profile) error {
|
||||
func (m *MockProfileRepository) Update(ctx context.Context, profile *model.Profile) error {
|
||||
if m.FailUpdate {
|
||||
return errors.New("mock update error")
|
||||
}
|
||||
@@ -174,14 +195,14 @@ func (m *MockProfileRepository) Update(profile *model.Profile) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *MockProfileRepository) UpdateFields(uuid string, updates map[string]interface{}) error {
|
||||
func (m *MockProfileRepository) UpdateFields(ctx context.Context, uuid string, updates map[string]interface{}) error {
|
||||
if m.FailUpdate {
|
||||
return errors.New("mock update error")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *MockProfileRepository) Delete(uuid string) error {
|
||||
func (m *MockProfileRepository) Delete(ctx context.Context, uuid string) error {
|
||||
if m.FailDelete {
|
||||
return errors.New("mock delete error")
|
||||
}
|
||||
@@ -189,19 +210,19 @@ func (m *MockProfileRepository) Delete(uuid string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *MockProfileRepository) CountByUserID(userID int64) (int64, error) {
|
||||
func (m *MockProfileRepository) CountByUserID(ctx context.Context, userID int64) (int64, error) {
|
||||
return int64(len(m.userProfiles[userID])), nil
|
||||
}
|
||||
|
||||
func (m *MockProfileRepository) SetActive(uuid string, userID int64) error {
|
||||
func (m *MockProfileRepository) SetActive(ctx context.Context, uuid string, userID int64) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *MockProfileRepository) UpdateLastUsedAt(uuid string) error {
|
||||
func (m *MockProfileRepository) UpdateLastUsedAt(ctx context.Context, uuid string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *MockProfileRepository) GetByNames(names []string) ([]*model.Profile, error) {
|
||||
func (m *MockProfileRepository) GetByNames(ctx context.Context, names []string) ([]*model.Profile, error) {
|
||||
var result []*model.Profile
|
||||
for _, name := range names {
|
||||
for _, profile := range m.profiles {
|
||||
@@ -213,14 +234,34 @@ func (m *MockProfileRepository) GetByNames(names []string) ([]*model.Profile, er
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func (m *MockProfileRepository) GetKeyPair(profileId string) (*model.KeyPair, error) {
|
||||
func (m *MockProfileRepository) GetKeyPair(ctx context.Context, profileId string) (*model.KeyPair, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (m *MockProfileRepository) UpdateKeyPair(profileId string, keyPair *model.KeyPair) error {
|
||||
func (m *MockProfileRepository) UpdateKeyPair(ctx context.Context, profileId string, keyPair *model.KeyPair) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// BatchUpdate / BatchDelete 仅用于满足接口
|
||||
func (m *MockProfileRepository) BatchUpdate(ctx context.Context, uuids []string, updates map[string]interface{}) (int64, error) {
|
||||
return 0, nil
|
||||
}
|
||||
|
||||
func (m *MockProfileRepository) BatchDelete(ctx context.Context, uuids []string) (int64, error) {
|
||||
return 0, nil
|
||||
}
|
||||
|
||||
// FindByUUIDs 批量查询 Profile
|
||||
func (m *MockProfileRepository) FindByUUIDs(ctx context.Context, uuids []string) ([]*model.Profile, error) {
|
||||
var result []*model.Profile
|
||||
for _, id := range uuids {
|
||||
if p, ok := m.profiles[id]; ok {
|
||||
result = append(result, p)
|
||||
}
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
|
||||
// MockTextureRepository 模拟TextureRepository
|
||||
type MockTextureRepository struct {
|
||||
textures map[int64]*model.Texture
|
||||
@@ -240,7 +281,7 @@ func NewMockTextureRepository() *MockTextureRepository {
|
||||
}
|
||||
}
|
||||
|
||||
func (m *MockTextureRepository) Create(texture *model.Texture) error {
|
||||
func (m *MockTextureRepository) Create(ctx context.Context, texture *model.Texture) error {
|
||||
if m.FailCreate {
|
||||
return errors.New("mock create error")
|
||||
}
|
||||
@@ -252,7 +293,7 @@ func (m *MockTextureRepository) Create(texture *model.Texture) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *MockTextureRepository) FindByID(id int64) (*model.Texture, error) {
|
||||
func (m *MockTextureRepository) FindByID(ctx context.Context, id int64) (*model.Texture, error) {
|
||||
if m.FailFind {
|
||||
return nil, errors.New("mock find error")
|
||||
}
|
||||
@@ -262,7 +303,7 @@ func (m *MockTextureRepository) FindByID(id int64) (*model.Texture, error) {
|
||||
return nil, errors.New("texture not found")
|
||||
}
|
||||
|
||||
func (m *MockTextureRepository) FindByHash(hash string) (*model.Texture, error) {
|
||||
func (m *MockTextureRepository) FindByHash(ctx context.Context, hash string) (*model.Texture, error) {
|
||||
if m.FailFind {
|
||||
return nil, errors.New("mock find error")
|
||||
}
|
||||
@@ -274,7 +315,7 @@ func (m *MockTextureRepository) FindByHash(hash string) (*model.Texture, error)
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (m *MockTextureRepository) FindByUploaderID(uploaderID int64, page, pageSize int) ([]*model.Texture, int64, error) {
|
||||
func (m *MockTextureRepository) FindByUploaderID(ctx context.Context, uploaderID int64, page, pageSize int) ([]*model.Texture, int64, error) {
|
||||
if m.FailFind {
|
||||
return nil, 0, errors.New("mock find error")
|
||||
}
|
||||
@@ -287,7 +328,7 @@ func (m *MockTextureRepository) FindByUploaderID(uploaderID int64, page, pageSiz
|
||||
return result, int64(len(result)), nil
|
||||
}
|
||||
|
||||
func (m *MockTextureRepository) Search(keyword string, textureType model.TextureType, publicOnly bool, page, pageSize int) ([]*model.Texture, int64, error) {
|
||||
func (m *MockTextureRepository) Search(ctx context.Context, keyword string, textureType model.TextureType, publicOnly bool, page, pageSize int) ([]*model.Texture, int64, error) {
|
||||
if m.FailFind {
|
||||
return nil, 0, errors.New("mock find error")
|
||||
}
|
||||
@@ -301,7 +342,7 @@ func (m *MockTextureRepository) Search(keyword string, textureType model.Texture
|
||||
return result, int64(len(result)), nil
|
||||
}
|
||||
|
||||
func (m *MockTextureRepository) Update(texture *model.Texture) error {
|
||||
func (m *MockTextureRepository) Update(ctx context.Context, texture *model.Texture) error {
|
||||
if m.FailUpdate {
|
||||
return errors.New("mock update error")
|
||||
}
|
||||
@@ -309,14 +350,14 @@ func (m *MockTextureRepository) Update(texture *model.Texture) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *MockTextureRepository) UpdateFields(id int64, fields map[string]interface{}) error {
|
||||
func (m *MockTextureRepository) UpdateFields(ctx context.Context, id int64, fields map[string]interface{}) error {
|
||||
if m.FailUpdate {
|
||||
return errors.New("mock update error")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *MockTextureRepository) Delete(id int64) error {
|
||||
func (m *MockTextureRepository) Delete(ctx context.Context, id int64) error {
|
||||
if m.FailDelete {
|
||||
return errors.New("mock delete error")
|
||||
}
|
||||
@@ -324,39 +365,39 @@ func (m *MockTextureRepository) Delete(id int64) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *MockTextureRepository) IncrementDownloadCount(id int64) error {
|
||||
func (m *MockTextureRepository) IncrementDownloadCount(ctx context.Context, id int64) error {
|
||||
if texture, ok := m.textures[id]; ok {
|
||||
texture.DownloadCount++
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *MockTextureRepository) IncrementFavoriteCount(id int64) error {
|
||||
func (m *MockTextureRepository) IncrementFavoriteCount(ctx context.Context, id int64) error {
|
||||
if texture, ok := m.textures[id]; ok {
|
||||
texture.FavoriteCount++
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *MockTextureRepository) DecrementFavoriteCount(id int64) error {
|
||||
func (m *MockTextureRepository) DecrementFavoriteCount(ctx context.Context, id int64) error {
|
||||
if texture, ok := m.textures[id]; ok && texture.FavoriteCount > 0 {
|
||||
texture.FavoriteCount--
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *MockTextureRepository) CreateDownloadLog(log *model.TextureDownloadLog) error {
|
||||
func (m *MockTextureRepository) CreateDownloadLog(ctx context.Context, log *model.TextureDownloadLog) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *MockTextureRepository) IsFavorited(userID, textureID int64) (bool, error) {
|
||||
func (m *MockTextureRepository) IsFavorited(ctx context.Context, userID, textureID int64) (bool, error) {
|
||||
if userFavs, ok := m.favorites[userID]; ok {
|
||||
return userFavs[textureID], nil
|
||||
}
|
||||
return false, nil
|
||||
}
|
||||
|
||||
func (m *MockTextureRepository) AddFavorite(userID, textureID int64) error {
|
||||
func (m *MockTextureRepository) AddFavorite(ctx context.Context, userID, textureID int64) error {
|
||||
if m.favorites[userID] == nil {
|
||||
m.favorites[userID] = make(map[int64]bool)
|
||||
}
|
||||
@@ -364,14 +405,14 @@ func (m *MockTextureRepository) AddFavorite(userID, textureID int64) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *MockTextureRepository) RemoveFavorite(userID, textureID int64) error {
|
||||
func (m *MockTextureRepository) RemoveFavorite(ctx context.Context, userID, textureID int64) error {
|
||||
if userFavs, ok := m.favorites[userID]; ok {
|
||||
delete(userFavs, textureID)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *MockTextureRepository) GetUserFavorites(userID int64, page, pageSize int) ([]*model.Texture, int64, error) {
|
||||
func (m *MockTextureRepository) GetUserFavorites(ctx context.Context, userID int64, page, pageSize int) ([]*model.Texture, int64, error) {
|
||||
var result []*model.Texture
|
||||
if userFavs, ok := m.favorites[userID]; ok {
|
||||
for textureID := range userFavs {
|
||||
@@ -383,7 +424,7 @@ func (m *MockTextureRepository) GetUserFavorites(userID int64, page, pageSize in
|
||||
return result, int64(len(result)), nil
|
||||
}
|
||||
|
||||
func (m *MockTextureRepository) CountByUploaderID(uploaderID int64) (int64, error) {
|
||||
func (m *MockTextureRepository) CountByUploaderID(ctx context.Context, uploaderID int64) (int64, error) {
|
||||
var count int64
|
||||
for _, texture := range m.textures {
|
||||
if texture.UploaderID == uploaderID {
|
||||
@@ -393,6 +434,34 @@ func (m *MockTextureRepository) CountByUploaderID(uploaderID int64) (int64, erro
|
||||
return count, nil
|
||||
}
|
||||
|
||||
// FindByIDs 批量查询 Texture
|
||||
func (m *MockTextureRepository) FindByIDs(ctx context.Context, ids []int64) ([]*model.Texture, error) {
|
||||
var result []*model.Texture
|
||||
for _, id := range ids {
|
||||
if tex, ok := m.textures[id]; ok {
|
||||
result = append(result, tex)
|
||||
}
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
|
||||
// BatchUpdate 仅用于满足接口
|
||||
func (m *MockTextureRepository) BatchUpdate(ctx context.Context, ids []int64, fields map[string]interface{}) (int64, error) {
|
||||
return 0, nil
|
||||
}
|
||||
|
||||
// BatchDelete 仅用于满足接口
|
||||
func (m *MockTextureRepository) BatchDelete(ctx context.Context, ids []int64) (int64, error) {
|
||||
var deleted int64
|
||||
for _, id := range ids {
|
||||
if _, ok := m.textures[id]; ok {
|
||||
delete(m.textures, id)
|
||||
deleted++
|
||||
}
|
||||
}
|
||||
return deleted, nil
|
||||
}
|
||||
|
||||
// MockTokenRepository 模拟TokenRepository
|
||||
type MockTokenRepository struct {
|
||||
tokens map[string]*model.Token
|
||||
@@ -409,7 +478,7 @@ func NewMockTokenRepository() *MockTokenRepository {
|
||||
}
|
||||
}
|
||||
|
||||
func (m *MockTokenRepository) Create(token *model.Token) error {
|
||||
func (m *MockTokenRepository) Create(ctx context.Context, token *model.Token) error {
|
||||
if m.FailCreate {
|
||||
return errors.New("mock create error")
|
||||
}
|
||||
@@ -418,7 +487,7 @@ func (m *MockTokenRepository) Create(token *model.Token) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *MockTokenRepository) FindByAccessToken(accessToken string) (*model.Token, error) {
|
||||
func (m *MockTokenRepository) FindByAccessToken(ctx context.Context, accessToken string) (*model.Token, error) {
|
||||
if m.FailFind {
|
||||
return nil, errors.New("mock find error")
|
||||
}
|
||||
@@ -428,14 +497,14 @@ func (m *MockTokenRepository) FindByAccessToken(accessToken string) (*model.Toke
|
||||
return nil, errors.New("token not found")
|
||||
}
|
||||
|
||||
func (m *MockTokenRepository) GetByUserID(userId int64) ([]*model.Token, error) {
|
||||
func (m *MockTokenRepository) GetByUserID(ctx context.Context, userId int64) ([]*model.Token, error) {
|
||||
if m.FailFind {
|
||||
return nil, errors.New("mock find error")
|
||||
}
|
||||
return m.userTokens[userId], nil
|
||||
}
|
||||
|
||||
func (m *MockTokenRepository) GetUUIDByAccessToken(accessToken string) (string, error) {
|
||||
func (m *MockTokenRepository) GetUUIDByAccessToken(ctx context.Context, accessToken string) (string, error) {
|
||||
if m.FailFind {
|
||||
return "", errors.New("mock find error")
|
||||
}
|
||||
@@ -445,7 +514,7 @@ func (m *MockTokenRepository) GetUUIDByAccessToken(accessToken string) (string,
|
||||
return "", errors.New("token not found")
|
||||
}
|
||||
|
||||
func (m *MockTokenRepository) GetUserIDByAccessToken(accessToken string) (int64, error) {
|
||||
func (m *MockTokenRepository) GetUserIDByAccessToken(ctx context.Context, accessToken string) (int64, error) {
|
||||
if m.FailFind {
|
||||
return 0, errors.New("mock find error")
|
||||
}
|
||||
@@ -455,7 +524,7 @@ func (m *MockTokenRepository) GetUserIDByAccessToken(accessToken string) (int64,
|
||||
return 0, errors.New("token not found")
|
||||
}
|
||||
|
||||
func (m *MockTokenRepository) DeleteByAccessToken(accessToken string) error {
|
||||
func (m *MockTokenRepository) DeleteByAccessToken(ctx context.Context, accessToken string) error {
|
||||
if m.FailDelete {
|
||||
return errors.New("mock delete error")
|
||||
}
|
||||
@@ -463,7 +532,7 @@ func (m *MockTokenRepository) DeleteByAccessToken(accessToken string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *MockTokenRepository) DeleteByUserID(userId int64) error {
|
||||
func (m *MockTokenRepository) DeleteByUserID(ctx context.Context, userId int64) error {
|
||||
if m.FailDelete {
|
||||
return errors.New("mock delete error")
|
||||
}
|
||||
@@ -474,7 +543,7 @@ func (m *MockTokenRepository) DeleteByUserID(userId int64) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *MockTokenRepository) BatchDelete(accessTokens []string) (int64, error) {
|
||||
func (m *MockTokenRepository) BatchDelete(ctx context.Context, accessTokens []string) (int64, error) {
|
||||
if m.FailDelete {
|
||||
return 0, errors.New("mock delete error")
|
||||
}
|
||||
@@ -499,14 +568,14 @@ func NewMockSystemConfigRepository() *MockSystemConfigRepository {
|
||||
}
|
||||
}
|
||||
|
||||
func (m *MockSystemConfigRepository) GetByKey(key string) (*model.SystemConfig, error) {
|
||||
func (m *MockSystemConfigRepository) GetByKey(ctx context.Context, key string) (*model.SystemConfig, error) {
|
||||
if config, ok := m.configs[key]; ok {
|
||||
return config, nil
|
||||
}
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (m *MockSystemConfigRepository) GetPublic() ([]model.SystemConfig, error) {
|
||||
func (m *MockSystemConfigRepository) GetPublic(ctx context.Context) ([]model.SystemConfig, error) {
|
||||
var result []model.SystemConfig
|
||||
for _, v := range m.configs {
|
||||
result = append(result, *v)
|
||||
@@ -514,7 +583,7 @@ func (m *MockSystemConfigRepository) GetPublic() ([]model.SystemConfig, error) {
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func (m *MockSystemConfigRepository) GetAll() ([]model.SystemConfig, error) {
|
||||
func (m *MockSystemConfigRepository) GetAll(ctx context.Context) ([]model.SystemConfig, error) {
|
||||
var result []model.SystemConfig
|
||||
for _, v := range m.configs {
|
||||
result = append(result, *v)
|
||||
@@ -522,12 +591,12 @@ func (m *MockSystemConfigRepository) GetAll() ([]model.SystemConfig, error) {
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func (m *MockSystemConfigRepository) Update(config *model.SystemConfig) error {
|
||||
func (m *MockSystemConfigRepository) Update(ctx context.Context, config *model.SystemConfig) error {
|
||||
m.configs[config.Key] = config
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *MockSystemConfigRepository) UpdateValue(key, value string) error {
|
||||
func (m *MockSystemConfigRepository) UpdateValue(ctx context.Context, key, value string) error {
|
||||
if config, ok := m.configs[key]; ok {
|
||||
config.Value = value
|
||||
return nil
|
||||
|
||||
Reference in New Issue
Block a user