refactor: 移除全局单例、修复分层违规、统一错误与响应
This commit is contained in:
@@ -130,6 +130,24 @@ func (m *MockUserRepository) FindByIDs(ctx context.Context, ids []int64) ([]*mod
|
||||
return result, nil
|
||||
}
|
||||
|
||||
// List 分页查询用户列表(管理员,mock 实现)
|
||||
func (m *MockUserRepository) List(ctx context.Context, page, pageSize int) ([]*model.User, int64, error) {
|
||||
var all []*model.User
|
||||
for _, u := range m.users {
|
||||
all = append(all, u)
|
||||
}
|
||||
total := int64(len(all))
|
||||
offset := (page - 1) * pageSize
|
||||
if offset >= len(all) {
|
||||
return []*model.User{}, total, nil
|
||||
}
|
||||
end := offset + pageSize
|
||||
if end > len(all) {
|
||||
end = len(all)
|
||||
}
|
||||
return all[offset:end], total, nil
|
||||
}
|
||||
|
||||
// MockProfileRepository 模拟ProfileRepository
|
||||
type MockProfileRepository struct {
|
||||
profiles map[string]*model.Profile
|
||||
@@ -474,6 +492,32 @@ func (m *MockTextureRepository) BatchDelete(ctx context.Context, ids []int64) (i
|
||||
return deleted, nil
|
||||
}
|
||||
|
||||
// ListForAdmin 管理员列表(mock 实现)
|
||||
func (m *MockTextureRepository) ListForAdmin(ctx context.Context, page, pageSize int) ([]*model.Texture, int64, error) {
|
||||
var all []*model.Texture
|
||||
for _, t := range m.textures {
|
||||
all = append(all, t)
|
||||
}
|
||||
total := int64(len(all))
|
||||
offset := (page - 1) * pageSize
|
||||
if offset >= len(all) {
|
||||
return []*model.Texture{}, total, nil
|
||||
}
|
||||
end := offset + pageSize
|
||||
if end > len(all) {
|
||||
end = len(all)
|
||||
}
|
||||
return all[offset:end], total, nil
|
||||
}
|
||||
|
||||
// FindByIDForAdmin 管理员查询(mock 实现,无权限过滤)
|
||||
func (m *MockTextureRepository) FindByIDForAdmin(ctx context.Context, id int64) (*model.Texture, error) {
|
||||
if t, ok := m.textures[id]; ok {
|
||||
return t, nil
|
||||
}
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
|
||||
// ============================================================================
|
||||
// Service Mocks
|
||||
|
||||
Reference in New Issue
Block a user