Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
Signed-off-by: andoriyaprashant <[email protected]>
  • Loading branch information
andoriyaprashant committed Jun 8, 2024
1 parent c83953b commit 37c96c5
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,31 @@ import (
"go.mongodb.org/mongo-driver/mongo"
)

type Operator struct {
operator mongodb.MongoOperator
}

func NewConfigOperator(mongodbOperator mongodb.MongoOperator) *Operator {
return &Operator{
operator: mongodbOperator,
}
}

// CreateConfig creates a new server config with unique key
func CreateConfig(ctx context.Context, config *ServerConfig, mongodbOperator mongodb.MongoOperator) error {
err := mongodbOperator.Create(ctx, mongodb.ServerConfigCollection, config)
func (o *Operator) CreateConfig(ctx context.Context, config *ServerConfig) error {
err := o.operator.Create(ctx, mongodb.ServerConfigCollection, config)
if err != nil {
return err
}
return nil
}

// GetConfig returns the requested server config
func GetConfig(ctx context.Context, key string, mongodbOperator mongodb.MongoOperator) (*ServerConfig, error) {
func (o *Operator) GetConfig(ctx context.Context, key string) (*ServerConfig, error) {
query := bson.D{
{"key", key},
}
results, err := mongodbOperator.Get(ctx, mongodb.ServerConfigCollection, query)
results, err := o.operator.Get(ctx, mongodb.ServerConfigCollection, query)
if err != nil {
return nil, err
}
Expand All @@ -39,16 +49,16 @@ func GetConfig(ctx context.Context, key string, mongodbOperator mongodb.MongoOpe
}

// UpdateConfig updates the required server config
func UpdateConfig(ctx context.Context, key string, value interface{}, mongodbOperator mongodb.MongoOperator) error {
func (o *Operator) UpdateConfig(ctx context.Context, key string, value interface{}) error {
query := bson.D{
{"key", key},
}
update := bson.D{{"$set", bson.D{{
"value", value}},
}}
_, err := mongodbOperator.Update(ctx, mongodb.ServerConfigCollection, query, update)
_, err := o.operator.Update(ctx, mongodb.ServerConfigCollection, query, update)
if err != nil {
return err
}
return nil
}
}
4 changes: 0 additions & 4 deletions chaoscenter/graphql/server/pkg/database/mongodb/operations.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,6 @@ type MongoOperations struct {
MongoClient *MongoClient
}

var (
// Operator contains all the CRUD operations of the mongo database

)

func NewMongoOperations(mongoClient *MongoClient) *MongoOperations {
return &MongoOperations{
Expand Down
4 changes: 2 additions & 2 deletions chaoscenter/graphql/server/pkg/handlers/readiness_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ func contains(s []string, str string) bool {
}

// ReadinessHandler returns a handler function for readiness checks
func (o *Operator) ReadinessHandler() gin.HandlerFunc {
func (r *Operator) ReadinessHandler() gin.HandlerFunc {
return func(c *gin.Context) {
var dbFlag = "up"
dbs, err := o.mongoOperator.ListDataBase(context.Background(), mongodb.MgoClient)
dbs, err := r.mongoOperator.ListDataBase(context.Background(), mongodb.MgoClient)
if err != nil {
dbFlag = "down"
}
Expand Down

0 comments on commit 37c96c5

Please sign in to comment.