Skip to content

Commit 263c165

Browse files
committed
feat: add resolvers and operations for applications
1 parent 38e835d commit 263c165

File tree

8 files changed

+680
-51
lines changed

8 files changed

+680
-51
lines changed
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
package core
2+
3+
import (
4+
"context"
5+
containermanger "github.com/swiftwave-org/swiftwave/container_manager"
6+
"gorm.io/gorm"
7+
)
8+
9+
// This file contains the operations for the Application model.
10+
// This functions will perform necessary validation before doing the actual database operation.
11+
12+
// Each function's argument format should be (ctx context.Context, db gorm.DB, ...)
13+
// context used to pass some data to the function e.g. user id, auth info, etc.
14+
15+
func IsExistApplicationName(ctx context.Context, db gorm.DB, dockerManager containermanger.Manager, name string) (bool, error) {
16+
// verify from database
17+
var count int64
18+
tx := db.Model(&Application{}).Where("name = ?", name).Count(&count)
19+
if tx.Error != nil {
20+
return false, tx.Error
21+
}
22+
if count > 0 {
23+
return true, nil
24+
}
25+
// verify from docker client
26+
_, err := dockerManager.GetService(name)
27+
if err == nil {
28+
return true, nil
29+
}
30+
return false, nil
31+
}
32+
33+
func FindAllApplications(ctx context.Context, db gorm.DB) ([]*Application, error) {
34+
var applications []*Application
35+
tx := db.Find(&applications)
36+
return applications, tx.Error
37+
}
38+
39+
func (application *Application) FindById(ctx context.Context, db gorm.DB, id string) error {
40+
tx := db.First(&application, id)
41+
return tx.Error
42+
}
43+
44+
func (application *Application) Create(ctx context.Context, db gorm.DB) error {
45+
// TODO: add validation, create new deployment
46+
tx := db.Create(&application)
47+
return tx.Error
48+
}
49+
50+
func (application *Application) Update(ctx context.Context, db gorm.DB) error {
51+
// TODO: add validation, create new deployment if change required
52+
tx := db.Save(&application)
53+
return tx.Error
54+
}
55+
56+
func (application *Application) Delete(ctx context.Context, db gorm.DB) error {
57+
// TODO: add validation, delete all deployments and application
58+
tx := db.Delete(&application)
59+
return tx.Error
60+
}

swiftwave_manager/core/models.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,10 @@ type Application struct {
103103
// No of replicas to be deployed
104104
DeploymentMode DeploymentMode `json:"deploymentMode"`
105105
Replicas uint `json:"replicas"`
106-
// Deployment
106+
// Deployments
107107
Deployments []Deployment `json:"deployments" gorm:"foreignKey:ApplicationID"`
108+
// Latest Deployment
109+
LatestDeployment Deployment `json:"-"`
108110
// Ingress Rules
109111
IngressRules []IngressRule `json:"ingressRules" gorm:"foreignKey:ApplicationID"`
110112
}

swiftwave_manager/core/types.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,12 @@ const (
7272
type DeploymentStatus string
7373

7474
const (
75+
DeploymentStatusPending DeploymentStatus = "pending"
7576
DeploymentStatusQueued DeploymentStatus = "queued"
7677
DeploymentStatusDeploying DeploymentStatus = "deploying"
77-
DeploymentStatusFailed DeploymentStatus = "failed"
7878
DeploymentStatusRunning DeploymentStatus = "running"
7979
DeploymentStatusStopped DeploymentStatus = "stopped"
80+
DeploymentStatusFailed DeploymentStatus = "failed"
8081
)
8182

8283
// ProtocolType : type of protocol for ingress rule

swiftwave_manager/graphql/application.resolvers.go

Lines changed: 65 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)