From 37c96c5c95ee19f11d3ba22f6731e6a2301d5ec4 Mon Sep 17 00:00:00 2001 From: andoriyaprashant Date: Sat, 8 Jun 2024 12:08:24 +0530 Subject: [PATCH] Update Signed-off-by: andoriyaprashant --- .../pkg/database/mongodb/config/operations.go | 24 +++++++++++++------ .../server/pkg/database/mongodb/operations.go | 4 ---- .../server/pkg/handlers/readiness_handler.go | 4 ++-- 3 files changed, 19 insertions(+), 13 deletions(-) diff --git a/chaoscenter/graphql/server/pkg/database/mongodb/config/operations.go b/chaoscenter/graphql/server/pkg/database/mongodb/config/operations.go index 5fd0c0ef5db..4953a137ceb 100644 --- a/chaoscenter/graphql/server/pkg/database/mongodb/config/operations.go +++ b/chaoscenter/graphql/server/pkg/database/mongodb/config/operations.go @@ -9,9 +9,19 @@ 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 } @@ -19,11 +29,11 @@ func CreateConfig(ctx context.Context, config *ServerConfig, mongodbOperator mon } // 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 } @@ -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 -} +} \ No newline at end of file diff --git a/chaoscenter/graphql/server/pkg/database/mongodb/operations.go b/chaoscenter/graphql/server/pkg/database/mongodb/operations.go index ba6531ac738..487d8b62864 100644 --- a/chaoscenter/graphql/server/pkg/database/mongodb/operations.go +++ b/chaoscenter/graphql/server/pkg/database/mongodb/operations.go @@ -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{ diff --git a/chaoscenter/graphql/server/pkg/handlers/readiness_handler.go b/chaoscenter/graphql/server/pkg/handlers/readiness_handler.go index ea075832919..1d143961d17 100644 --- a/chaoscenter/graphql/server/pkg/handlers/readiness_handler.go +++ b/chaoscenter/graphql/server/pkg/handlers/readiness_handler.go @@ -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" }