Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions internal/models/profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ type CreateProfileRequest struct {
ProjectsDir string `json:"projectsDir"`
JavaHomeOverride string `json:"javaHomeOverride"`
IsDefault bool `json:"isDefault"`
IsActive bool `json:"isActive"`
}

type UpdateProfileRequest struct {
Expand Down
19 changes: 16 additions & 3 deletions internal/services/profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,13 @@ func (ps *ProfileService) CreateServiceProfile(userID string, req *models.Create
}
}

// Handle active profile logic
if req.IsActive {
if err := ps.clearActiveProfiles(userID); err != nil {
return nil, fmt.Errorf("failed to clear existing active profiles: %w", err)
}
}

// Validate services exist (temporarily disabled for debugging)
log.Printf("[DEBUG] Skipping service validation for debugging purposes")
// if err := ps.validateServices(req.Services); err != nil {
Expand All @@ -261,10 +268,10 @@ func (ps *ProfileService) CreateServiceProfile(userID string, req *models.Create
return nil, fmt.Errorf("failed to marshal env vars: %w", err)
}

query := `INSERT INTO service_profiles (id, user_id, name, description, services_json, env_vars_json, projects_dir, java_home_override, is_default, created_at, updated_at)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP)`
query := `INSERT INTO service_profiles (id, user_id, name, description, services_json, env_vars_json, projects_dir, java_home_override, is_default, is_active, created_at, updated_at)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP)`

_, err = ps.db.Exec(query, profileID, userID, req.Name, req.Description, string(servicesJSON), string(envVarsJSON), req.ProjectsDir, req.JavaHomeOverride, req.IsDefault)
_, err = ps.db.Exec(query, profileID, userID, req.Name, req.Description, string(servicesJSON), string(envVarsJSON), req.ProjectsDir, req.JavaHomeOverride, req.IsDefault, req.IsActive)
if err != nil {
return nil, fmt.Errorf("failed to create service profile: %w", err)
}
Expand Down Expand Up @@ -719,6 +726,12 @@ func (ps *ProfileService) clearDefaultProfiles(userID string) error {
return err
}

func (ps *ProfileService) clearActiveProfiles(userID string) error {
query := `UPDATE service_profiles SET is_active = FALSE WHERE user_id = ? AND is_active = TRUE`
_, err := ps.db.Exec(query, userID)
return err
}

func (ps *ProfileService) validateServices(serviceNames []string) error {
if ps.sm == nil {
log.Printf("[WARN] Service manager not available, skipping service validation")
Expand Down
Loading
Loading