Skip to content

Commit

Permalink
feat: gql queries for application group added (#482)
Browse files Browse the repository at this point in the history
  • Loading branch information
tanmoysrt authored Apr 8, 2024
1 parent b0d8a3d commit efcf9ed
Show file tree
Hide file tree
Showing 7 changed files with 418 additions and 16 deletions.
50 changes: 41 additions & 9 deletions swiftwave_service/core/application.operations.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,15 @@ func FindAllApplications(ctx context.Context, db gorm.DB) ([]*Application, error
return applications, tx.Error
}

func FindApplicationsByGroup(ctx context.Context, db gorm.DB, group string) ([]*Application, error) {
var applications []*Application
err := db.Model(&Application{}).Where("application_group = ?", group).Scan(&applications).Error
if err != nil {
return nil, err
}
return applications, nil
}

func (application *Application) FindById(ctx context.Context, db gorm.DB, id string) error {
tx := db.Where("id = ?", id).First(&application)
if tx.Error != nil {
Expand Down Expand Up @@ -106,15 +115,15 @@ func (application *Application) Create(ctx context.Context, db gorm.DB, dockerMa
}
// create application
createdApplication := Application{
ID: uuid.NewString(),
Name: application.Name,
DeploymentMode: application.DeploymentMode,
Replicas: application.Replicas,
WebhookToken: uuid.NewString(),
Command: application.Command,
Capabilities: application.Capabilities,
Sysctls: application.Sysctls,
Group: application.Group,
ID: uuid.NewString(),
Name: application.Name,
DeploymentMode: application.DeploymentMode,
Replicas: application.Replicas,
WebhookToken: uuid.NewString(),
Command: application.Command,
Capabilities: application.Capabilities,
Sysctls: application.Sysctls,
ApplicationGroup: application.ApplicationGroup,
}
tx := db.Create(&createdApplication)
if tx.Error != nil {
Expand Down Expand Up @@ -524,3 +533,26 @@ func (application *Application) MarkAsWake(ctx context.Context, db gorm.DB) erro
tx := db.Model(&application).Update("is_sleeping", false)
return tx.Error
}

func (application *Application) UpdateGroup(ctx context.Context, db gorm.DB, group string) error {
err := application.FindById(ctx, db, application.ID)
if err != nil {
return err
}
return db.Model(&application).Update("application_group", group).Error
}

func FetchApplicationGroups(ctx context.Context, db gorm.DB) ([]string, error) {
var groups []string
err := db.Model(&Application{}).Select("application_group").Where("application_group IS NOT NULL").Group("application_group").Scan(&groups).Error
if err != nil {
return nil, err
}
// remove "" from slice
for i, group := range groups {
if group == "" {
groups = append(groups[:i], groups[i+1:]...)
}
}
return groups, err
}
4 changes: 2 additions & 2 deletions swiftwave_service/core/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,8 @@ type Application struct {
IsSleeping bool `json:"is_sleeping" gorm:"default:false"`
// Resource Stats
ResourceStats []ApplicationServiceResourceStat `json:"resource_stats" gorm:"foreignKey:ApplicationID;constraint:OnUpdate:CASCADE,OnDelete:CASCADE"`
// Application Group
Group string `json:"group"`
// Application ApplicationGroup
ApplicationGroup string `json:"application_group"`
}

// Deployment : hold information about deployment of application
Expand Down
48 changes: 47 additions & 1 deletion swiftwave_service/graphql/application.resolvers.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit efcf9ed

Please sign in to comment.