refactor: Update tenant ID handling across the application

This commit is contained in:
wizardchen
2025-11-25 16:30:54 +08:00
parent 9f6f5f5773
commit 64c44c9e27
78 changed files with 437 additions and 601 deletions
+5 -5
View File
@@ -101,7 +101,7 @@ func (s *modelService) GetModelByID(ctx context.Context, id string) (*types.Mode
return nil, errors.New("model ID cannot be empty")
}
tenantID := ctx.Value(types.TenantIDContextKey).(uint)
tenantID := ctx.Value(types.TenantIDContextKey).(uint64)
// Fetch model from repository
model, err := s.repo.GetByID(ctx, tenantID, id)
@@ -145,7 +145,7 @@ func (s *modelService) GetModelByID(ctx context.Context, id string) (*types.Mode
func (s *modelService) ListModels(ctx context.Context) ([]*types.Model, error) {
logger.Info(ctx, "Start listing models")
tenantID := ctx.Value(types.TenantIDContextKey).(uint)
tenantID := ctx.Value(types.TenantIDContextKey).(uint64)
logger.Infof(ctx, "Listing models for tenant ID: %d", tenantID)
// List models from repository with no additional filters
@@ -167,7 +167,7 @@ func (s *modelService) UpdateModel(ctx context.Context, model *types.Model) erro
logger.Infof(ctx, "Updating model ID: %s, name: %s", model.ID, model.Name)
// Check if the model is builtin - builtin models cannot be updated
tenantID := ctx.Value(types.TenantIDContextKey).(uint)
tenantID := ctx.Value(types.TenantIDContextKey).(uint64)
existingModel, err := s.repo.GetByID(ctx, tenantID, model.ID)
if err != nil {
logger.ErrorWithFields(ctx, err, map[string]interface{}{
@@ -199,7 +199,7 @@ func (s *modelService) DeleteModel(ctx context.Context, id string) error {
logger.Info(ctx, "Start deleting model")
logger.Infof(ctx, "Deleting model ID: %s", id)
tenantID := ctx.Value(types.TenantIDContextKey).(uint)
tenantID := ctx.Value(types.TenantIDContextKey).(uint64)
logger.Infof(ctx, "Tenant ID: %d", tenantID)
// Check if the model is builtin - builtin models cannot be deleted
@@ -308,7 +308,7 @@ func (s *modelService) GetChatModel(ctx context.Context, modelId string) (chat.C
return nil, errors.New("model ID cannot be empty")
}
tenantID := ctx.Value(types.TenantIDContextKey).(uint)
tenantID := ctx.Value(types.TenantIDContextKey).(uint64)
// Get the model directly from repository to avoid status checks
model, err := s.repo.GetByID(ctx, tenantID, modelId)