From 0d9fe394dd3173995e954f589a0aeb8291bcbf00 Mon Sep 17 00:00:00 2001 From: prdai Date: Wed, 13 May 2026 13:15:55 +0530 Subject: [PATCH 01/10] chore: rename mongodb client functions from [CRUD]Entity to [CRUD]Metadata fixes: https://github.com/LDFLK/OpenGIN/issues/340 --- .../db/repository/mongo/metadata_handler.go | 10 +++++----- .../db/repository/mongo/mongodb_client.go | 16 +++++++-------- .../repository/mongo/mongodb_client_test.go | 20 +++++++++---------- 3 files changed, 23 insertions(+), 23 deletions(-) diff --git a/opengin/core-api/db/repository/mongo/metadata_handler.go b/opengin/core-api/db/repository/mongo/metadata_handler.go index d5aed45e..f36706bd 100644 --- a/opengin/core-api/db/repository/mongo/metadata_handler.go +++ b/opengin/core-api/db/repository/mongo/metadata_handler.go @@ -23,7 +23,7 @@ func (repo *MongoRepository) HandleMetadata(ctx context.Context, entityId string } // Check if metadata for entity already exists - existingEntity, err := repo.ReadEntity(ctx, entityId) + existingEntity, err := repo.ReadMetadata(ctx, entityId) if err != nil && err != mongo.ErrNoDocuments { return err } @@ -40,12 +40,12 @@ func (repo *MongoRepository) HandleMetadata(ctx context.Context, entityId string Attributes: entity.Attributes, Relationships: entity.Relationships, } - _, err = repo.CreateEntity(ctx, newEntity) + _, err = repo.CreateMetadata(ctx, newEntity) } else { // Update existing entity's metadata // TODO: Should we choose _id for placing our id or should we use id field separately and use that. // Because then it is going to be reading or deleting or whatever by filtering using an attribute not the id of the object. - _, err = repo.UpdateEntity(ctx, existingEntity.Id, bson.M{"metadata": entity.GetMetadata()}) + _, err = repo.UpdateMetadata(ctx, existingEntity.Id, bson.M{"metadata": entity.GetMetadata()}) } return err @@ -53,8 +53,8 @@ func (repo *MongoRepository) HandleMetadata(ctx context.Context, entityId string // Improved GetMetadata function that handles conversion internally func (repo *MongoRepository) GetMetadata(ctx context.Context, entityId string) (map[string]*anypb.Any, error) { - // Use the existing ReadEntity method for consistency - entity, err := repo.ReadEntity(ctx, entityId) + // Use the existing method for consistency + entity, err := repo.ReadMetadata(ctx, entityId) if err != nil { // Log error and return empty metadata map log.Printf("Error retrieving metadata for entity %s: %v", entityId, err) diff --git a/opengin/core-api/db/repository/mongo/mongodb_client.go b/opengin/core-api/db/repository/mongo/mongodb_client.go index 6a770e7e..6a5acf49 100644 --- a/opengin/core-api/db/repository/mongo/mongodb_client.go +++ b/opengin/core-api/db/repository/mongo/mongodb_client.go @@ -74,17 +74,17 @@ func (repo *MongoRepository) collection() *mongo.Collection { return repo.client.Database(repo.config.DBName).Collection(repo.config.Collection) } -// CreateEntity inserts a new entity in MongoDB +// CreateMetadata inserts a new entity in MongoDB // FIXME: https://github.com/LDFLK/nexoan/issues/118 -func (repo *MongoRepository) CreateEntity(ctx context.Context, entity *pb.Entity) (*mongo.InsertOneResult, error) { +func (repo *MongoRepository) CreateMetadata(ctx context.Context, entity *pb.Entity) (*mongo.InsertOneResult, error) { // Use the entity.Id as MongoDB's _id field doc := toDocument(entity) result, err := repo.collection().InsertOne(ctx, doc) return result, err } -// ReadEntity fetches an entity by ID from MongoDB -func (repo *MongoRepository) ReadEntity(ctx context.Context, id string) (*pb.Entity, error) { +// ReadMetadata fetches an entity by ID from MongoDB +func (repo *MongoRepository) ReadMetadata(ctx context.Context, id string) (*pb.Entity, error) { var doc entityDocument err := repo.collection().FindOne(ctx, bson.M{"_id": id}).Decode(&doc) if err != nil { @@ -93,15 +93,15 @@ func (repo *MongoRepository) ReadEntity(ctx context.Context, id string) (*pb.Ent return fromDocument(&doc), nil } -// UpdateEntity updates an entity's attributes in MongoDB -func (repo *MongoRepository) UpdateEntity(ctx context.Context, id string, updates bson.M) (*mongo.UpdateResult, error) { +// UpdateMetadata updates an entity's attributes in MongoDB +func (repo *MongoRepository) UpdateMetadata(ctx context.Context, id string, updates bson.M) (*mongo.UpdateResult, error) { update := bson.M{"$set": updates} result, err := repo.collection().UpdateOne(ctx, bson.M{"_id": id}, update) return result, err } -// DeleteEntity removes an entity from MongoDB -func (repo *MongoRepository) DeleteEntity(ctx context.Context, id string) (*mongo.DeleteResult, error) { +// DeleteMetadata removes an entity from MongoDB +func (repo *MongoRepository) DeleteMetadata(ctx context.Context, id string) (*mongo.DeleteResult, error) { result, err := repo.collection().DeleteOne(ctx, bson.M{"_id": id}) return result, err } diff --git a/opengin/core-api/db/repository/mongo/mongodb_client_test.go b/opengin/core-api/db/repository/mongo/mongodb_client_test.go index 5f659194..d96d1d3d 100644 --- a/opengin/core-api/db/repository/mongo/mongodb_client_test.go +++ b/opengin/core-api/db/repository/mongo/mongodb_client_test.go @@ -96,13 +96,13 @@ func TestCreateAndReadEntity(t *testing.T) { } // Create entity - result, err := testRepo.CreateEntity(testCtx, entity) + result, err := testRepo.CreateMetadata(testCtx, entity) assert.NoError(t, err) assert.NotNil(t, result, "Insert result should not be nil") log.Printf("Inserted document with ID: %v", result.InsertedID) // Read entity with error check - readEntity, err := testRepo.ReadEntity(testCtx, entityID) + readEntity, err := testRepo.ReadMetadata(testCtx, entityID) if err != nil { t.Fatalf("Failed to read entity: %v", err) } @@ -146,7 +146,7 @@ func TestUpdateEntityMetadata(t *testing.T) { } // Create entity - _, err = testRepo.CreateEntity(testCtx, entity) + _, err = testRepo.CreateMetadata(testCtx, entity) assert.NoError(t, err) // Update metadata @@ -159,13 +159,13 @@ func TestUpdateEntityMetadata(t *testing.T) { updatedMetadata["key3"] = val3 // Add new key // Update entity - _, err = testRepo.UpdateEntity(testCtx, entityID, map[string]interface{}{ + _, err = testRepo.UpdateMetadata(testCtx, entityID, map[string]interface{}{ "metadata": updatedMetadata, }) assert.NoError(t, err) // Read updated entity - readEntity, err := testRepo.ReadEntity(testCtx, entityID) + readEntity, err := testRepo.ReadMetadata(testCtx, entityID) assert.NoError(t, err) // Verify updated metadata @@ -201,16 +201,16 @@ func TestDeleteEntity(t *testing.T) { } // Create entity - _, err = testRepo.CreateEntity(testCtx, entity) + _, err = testRepo.CreateMetadata(testCtx, entity) assert.NoError(t, err) // Delete entity - result, err := testRepo.DeleteEntity(testCtx, entityID) + result, err := testRepo.DeleteMetadata(testCtx, entityID) assert.NoError(t, err) assert.Equal(t, int64(1), result.DeletedCount) // Verify entity is deleted - _, err = testRepo.ReadEntity(testCtx, entityID) + _, err = testRepo.ReadMetadata(testCtx, entityID) assert.Error(t, err) // Should return an error since entity doesn't exist } @@ -250,12 +250,12 @@ func TestMetadataHandling(t *testing.T) { } // Create entity - this should use the entityID as the document ID - result, err := testRepo.CreateEntity(testCtx, entity) + result, err := testRepo.CreateMetadata(testCtx, entity) assert.NoError(t, err) assert.NotNil(t, result, "Insert result should not be nil") // Read entity to verify metadata was stored correctly - readEntity, err := testRepo.ReadEntity(testCtx, entityID) + readEntity, err := testRepo.ReadMetadata(testCtx, entityID) assert.NoError(t, err) // Verify metadata with different value types From 7f51f64e6265b45a9648e243057e8134111114ec Mon Sep 17 00:00:00 2001 From: Ranuga <79456372+prdai@users.noreply.github.com> Date: Wed, 13 May 2026 13:23:03 +0530 Subject: [PATCH 02/10] Update opengin/core-api/db/repository/mongo/mongodb_client.go Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> --- opengin/core-api/db/repository/mongo/mongodb_client.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/opengin/core-api/db/repository/mongo/mongodb_client.go b/opengin/core-api/db/repository/mongo/mongodb_client.go index 6a5acf49..d2eef965 100644 --- a/opengin/core-api/db/repository/mongo/mongodb_client.go +++ b/opengin/core-api/db/repository/mongo/mongodb_client.go @@ -74,7 +74,7 @@ func (repo *MongoRepository) collection() *mongo.Collection { return repo.client.Database(repo.config.DBName).Collection(repo.config.Collection) } -// CreateMetadata inserts a new entity in MongoDB +// CreateMetadata inserts new metadata in MongoDB // FIXME: https://github.com/LDFLK/nexoan/issues/118 func (repo *MongoRepository) CreateMetadata(ctx context.Context, entity *pb.Entity) (*mongo.InsertOneResult, error) { // Use the entity.Id as MongoDB's _id field From 75de9fdc668f4bfc07225a0a140cca5202db1279 Mon Sep 17 00:00:00 2001 From: Ranuga <79456372+prdai@users.noreply.github.com> Date: Wed, 13 May 2026 13:23:15 +0530 Subject: [PATCH 03/10] Update opengin/core-api/db/repository/mongo/mongodb_client.go Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> --- opengin/core-api/db/repository/mongo/mongodb_client.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/opengin/core-api/db/repository/mongo/mongodb_client.go b/opengin/core-api/db/repository/mongo/mongodb_client.go index d2eef965..88cd8aee 100644 --- a/opengin/core-api/db/repository/mongo/mongodb_client.go +++ b/opengin/core-api/db/repository/mongo/mongodb_client.go @@ -83,7 +83,7 @@ func (repo *MongoRepository) CreateMetadata(ctx context.Context, entity *pb.Enti return result, err } -// ReadMetadata fetches an entity by ID from MongoDB +// ReadMetadata fetches metadata by ID from MongoDB func (repo *MongoRepository) ReadMetadata(ctx context.Context, id string) (*pb.Entity, error) { var doc entityDocument err := repo.collection().FindOne(ctx, bson.M{"_id": id}).Decode(&doc) From c0db719e07aa7bb55722383fed2bb58625af2d5c Mon Sep 17 00:00:00 2001 From: Ranuga <79456372+prdai@users.noreply.github.com> Date: Wed, 13 May 2026 13:23:24 +0530 Subject: [PATCH 04/10] Update opengin/core-api/db/repository/mongo/mongodb_client.go Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> --- opengin/core-api/db/repository/mongo/mongodb_client.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/opengin/core-api/db/repository/mongo/mongodb_client.go b/opengin/core-api/db/repository/mongo/mongodb_client.go index 88cd8aee..a4c7f2d4 100644 --- a/opengin/core-api/db/repository/mongo/mongodb_client.go +++ b/opengin/core-api/db/repository/mongo/mongodb_client.go @@ -93,7 +93,7 @@ func (repo *MongoRepository) ReadMetadata(ctx context.Context, id string) (*pb.E return fromDocument(&doc), nil } -// UpdateMetadata updates an entity's attributes in MongoDB +// UpdateMetadata updates metadata in MongoDB func (repo *MongoRepository) UpdateMetadata(ctx context.Context, id string, updates bson.M) (*mongo.UpdateResult, error) { update := bson.M{"$set": updates} result, err := repo.collection().UpdateOne(ctx, bson.M{"_id": id}, update) From 7ca2e59b13ffc6a27a9c702ba65e4b19597a6d52 Mon Sep 17 00:00:00 2001 From: Ranuga <79456372+prdai@users.noreply.github.com> Date: Wed, 13 May 2026 13:23:32 +0530 Subject: [PATCH 05/10] Update opengin/core-api/db/repository/mongo/mongodb_client.go Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> --- opengin/core-api/db/repository/mongo/mongodb_client.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/opengin/core-api/db/repository/mongo/mongodb_client.go b/opengin/core-api/db/repository/mongo/mongodb_client.go index a4c7f2d4..64e0e0d0 100644 --- a/opengin/core-api/db/repository/mongo/mongodb_client.go +++ b/opengin/core-api/db/repository/mongo/mongodb_client.go @@ -100,7 +100,7 @@ func (repo *MongoRepository) UpdateMetadata(ctx context.Context, id string, upda return result, err } -// DeleteMetadata removes an entity from MongoDB +// DeleteMetadata removes metadata from MongoDB func (repo *MongoRepository) DeleteMetadata(ctx context.Context, id string) (*mongo.DeleteResult, error) { result, err := repo.collection().DeleteOne(ctx, bson.M{"_id": id}) return result, err From 84a503ebba23e7d05519fdfa1af2999b06e811df Mon Sep 17 00:00:00 2001 From: Ranuga <79456372+prdai@users.noreply.github.com> Date: Wed, 13 May 2026 13:23:39 +0530 Subject: [PATCH 06/10] Update opengin/core-api/db/repository/mongo/metadata_handler.go Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> --- opengin/core-api/db/repository/mongo/metadata_handler.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/opengin/core-api/db/repository/mongo/metadata_handler.go b/opengin/core-api/db/repository/mongo/metadata_handler.go index f36706bd..0c13377c 100644 --- a/opengin/core-api/db/repository/mongo/metadata_handler.go +++ b/opengin/core-api/db/repository/mongo/metadata_handler.go @@ -53,7 +53,7 @@ func (repo *MongoRepository) HandleMetadata(ctx context.Context, entityId string // Improved GetMetadata function that handles conversion internally func (repo *MongoRepository) GetMetadata(ctx context.Context, entityId string) (map[string]*anypb.Any, error) { - // Use the existing method for consistency +// Use the existing ReadMetadata method for consistency entity, err := repo.ReadMetadata(ctx, entityId) if err != nil { // Log error and return empty metadata map From d750f6787daab647158b3fafefe60283138a1ce0 Mon Sep 17 00:00:00 2001 From: Ranuga <79456372+prdai@users.noreply.github.com> Date: Wed, 13 May 2026 13:28:00 +0530 Subject: [PATCH 07/10] Potential fix for pull request finding Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> --- opengin/core-api/db/repository/mongo/metadata_handler.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/opengin/core-api/db/repository/mongo/metadata_handler.go b/opengin/core-api/db/repository/mongo/metadata_handler.go index 0c13377c..55dd4b50 100644 --- a/opengin/core-api/db/repository/mongo/metadata_handler.go +++ b/opengin/core-api/db/repository/mongo/metadata_handler.go @@ -53,7 +53,7 @@ func (repo *MongoRepository) HandleMetadata(ctx context.Context, entityId string // Improved GetMetadata function that handles conversion internally func (repo *MongoRepository) GetMetadata(ctx context.Context, entityId string) (map[string]*anypb.Any, error) { -// Use the existing ReadMetadata method for consistency + // Use the existing ReadMetadata method for consistency entity, err := repo.ReadMetadata(ctx, entityId) if err != nil { // Log error and return empty metadata map From de4c804efc25007a0987de4abcdf59d0322b1ad7 Mon Sep 17 00:00:00 2001 From: prdai Date: Wed, 13 May 2026 13:33:50 +0530 Subject: [PATCH 08/10] chore: update callers to use renamed [CRUD]Metadata functions --- opengin/core-api/cmd/server/service.go | 4 ++-- opengin/core-api/engine/graph_metadata_manager.go | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/opengin/core-api/cmd/server/service.go b/opengin/core-api/cmd/server/service.go index 91215d85..df81379c 100644 --- a/opengin/core-api/cmd/server/service.go +++ b/opengin/core-api/cmd/server/service.go @@ -304,14 +304,14 @@ func (s *Server) DeleteEntity(ctx context.Context, req *pb.EntityId) (*pb.Empty, log.Printf("[server.DeleteEntity] Deleting Entity metadata: %s", req.Id) // Check if entity exists before deleting - _, err := s.mongoRepo.ReadEntity(ctx, req.Id) + _, err := s.mongoRepo.ReadMetadata(ctx, req.Id) if err != nil { // NOTE: Not returning an error here because we want to delete the // entity even if it does not contain metadata log.Printf("[server.DeleteEntity] Entity %s does not contain metadata: %v", req.Id, err) } else { log.Printf("[server.DeleteEntity] Entity %s metadata exists.", req.Id) - _, err = s.mongoRepo.DeleteEntity(ctx, req.Id) + _, err = s.mongoRepo.DeleteMetadata(ctx, req.Id) if err != nil { // Log error log.Printf("[server.DeleteEntity] Error deleting metadata for entity %s: %v", req.Id, err) diff --git a/opengin/core-api/engine/graph_metadata_manager.go b/opengin/core-api/engine/graph_metadata_manager.go index 9092dfda..ac35a29f 100644 --- a/opengin/core-api/engine/graph_metadata_manager.go +++ b/opengin/core-api/engine/graph_metadata_manager.go @@ -220,12 +220,12 @@ func (g *GraphMetadataManager) createAttributeLookUpGraph(ctx context.Context, m } // Check if the attribute metadata already exists - existingMetadata, err := mongoRepository.ReadEntity(ctx, metadata.AttributeID) + existingMetadata, err := mongoRepository.ReadMetadata(ctx, metadata.AttributeID) if err == nil && existingMetadata != nil { log.Printf("[GraphMetadataManager.CreateAttribute] Attribute metadata already exists: %s, skipping creation", metadata.AttributeID) } else { // Metadata doesn't exist, create it - _, err = mongoRepository.CreateEntity(ctx, attributeNode) + _, err = mongoRepository.CreateMetadata(ctx, attributeNode) if err != nil { log.Printf("[GraphMetadataManager.CreateAttribute] Error creating attribute metadata: %v", err) return err @@ -341,7 +341,7 @@ func (g *GraphMetadataManager) GetAttribute(ctx context.Context, entityID string log.Printf("[GraphMetadataManager.GetAttribute] Error getting Mongo repository: %v", err) return nil, err } - attributeMetadataEntity, err := mongoRepository.ReadEntity(ctx, targetAttributeID) + attributeMetadataEntity, err := mongoRepository.ReadMetadata(ctx, targetAttributeID) if err != nil { log.Printf("[GraphMetadataManager.GetAttribute] Error getting attribute metadata from MongoDB for attribute %s (entity %s): %v", targetAttributeID, entityID, err) return nil, fmt.Errorf("failed to get attribute metadata from MongoDB for attribute %s (entity %s): %w", targetAttributeID, entityID, err) @@ -417,7 +417,7 @@ func (g *GraphMetadataManager) ListAttributes(ctx context.Context, entityID stri log.Printf("[GraphMetadataManager.ListAttributes] Error getting Mongo repository: %v", err) return nil, err } - attributeMetadataEntity, err := mongoRepository.ReadEntity(ctx, attributeID) + attributeMetadataEntity, err := mongoRepository.ReadMetadata(ctx, attributeID) if err != nil { log.Printf("[GraphMetadataManager.ListAttributes] Error getting attribute metadata from MongoDB for attribute %s (entity %s): %v", attributeID, entityID, err) return nil, fmt.Errorf("failed to get attribute metadata from MongoDB for attribute %s (entity %s): %w", attributeID, entityID, err) From f3aa6ef24f9ad1bf41cd9b8ec6d47ef3b1fc1bcd Mon Sep 17 00:00:00 2001 From: prdai Date: Wed, 13 May 2026 13:44:49 +0530 Subject: [PATCH 09/10] docs: update test comments to refer to metadata after rename --- .../repository/mongo/mongodb_client_test.go | 26 +++++++++---------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/opengin/core-api/db/repository/mongo/mongodb_client_test.go b/opengin/core-api/db/repository/mongo/mongodb_client_test.go index d96d1d3d..36caae76 100644 --- a/opengin/core-api/db/repository/mongo/mongodb_client_test.go +++ b/opengin/core-api/db/repository/mongo/mongodb_client_test.go @@ -95,19 +95,19 @@ func TestCreateAndReadEntity(t *testing.T) { Metadata: metadata, } - // Create entity + // Create metadata result, err := testRepo.CreateMetadata(testCtx, entity) assert.NoError(t, err) assert.NotNil(t, result, "Insert result should not be nil") log.Printf("Inserted document with ID: %v", result.InsertedID) - // Read entity with error check + // Read metadata with error check readEntity, err := testRepo.ReadMetadata(testCtx, entityID) if err != nil { - t.Fatalf("Failed to read entity: %v", err) + t.Fatalf("Failed to read metadata: %v", err) } if readEntity == nil { - t.Fatal("Entity not found after creation") + t.Fatal("Metadata not found after creation") } // Verify entity data @@ -145,7 +145,7 @@ func TestUpdateEntityMetadata(t *testing.T) { Metadata: metadata, } - // Create entity + // Create metadata _, err = testRepo.CreateMetadata(testCtx, entity) assert.NoError(t, err) @@ -158,13 +158,13 @@ func TestUpdateEntityMetadata(t *testing.T) { updatedMetadata["key1"] = val2 // Update existing key updatedMetadata["key3"] = val3 // Add new key - // Update entity + // Update metadata _, err = testRepo.UpdateMetadata(testCtx, entityID, map[string]interface{}{ "metadata": updatedMetadata, }) assert.NoError(t, err) - // Read updated entity + // Read updated metadata readEntity, err := testRepo.ReadMetadata(testCtx, entityID) assert.NoError(t, err) @@ -200,18 +200,18 @@ func TestDeleteEntity(t *testing.T) { Metadata: metadata, } - // Create entity + // Create metadata _, err = testRepo.CreateMetadata(testCtx, entity) assert.NoError(t, err) - // Delete entity + // Delete metadata result, err := testRepo.DeleteMetadata(testCtx, entityID) assert.NoError(t, err) assert.Equal(t, int64(1), result.DeletedCount) - // Verify entity is deleted + // Verify metadata is deleted _, err = testRepo.ReadMetadata(testCtx, entityID) - assert.Error(t, err) // Should return an error since entity doesn't exist + assert.Error(t, err) // Should return an error since metadata doesn't exist } // TestMetadataHandling verifies the handling of complex metadata with various data types: @@ -249,12 +249,12 @@ func TestMetadataHandling(t *testing.T) { Metadata: metadata, } - // Create entity - this should use the entityID as the document ID + // Create metadata - this should use the entityID as the document ID result, err := testRepo.CreateMetadata(testCtx, entity) assert.NoError(t, err) assert.NotNil(t, result, "Insert result should not be nil") - // Read entity to verify metadata was stored correctly + // Read metadata to verify it was stored correctly readEntity, err := testRepo.ReadMetadata(testCtx, entityID) assert.NoError(t, err) From 77e2bc9d781d9fc434d37ebecdf0aefaf6076a54 Mon Sep 17 00:00:00 2001 From: prdai Date: Wed, 13 May 2026 13:51:45 +0530 Subject: [PATCH 10/10] docs: rename tests and comments to reflect metadata semantics --- opengin/core-api/cmd/server/service.go | 2 +- .../repository/mongo/mongodb_client_test.go | 37 +++++++++---------- 2 files changed, 19 insertions(+), 20 deletions(-) diff --git a/opengin/core-api/cmd/server/service.go b/opengin/core-api/cmd/server/service.go index df81379c..1f58c3d8 100644 --- a/opengin/core-api/cmd/server/service.go +++ b/opengin/core-api/cmd/server/service.go @@ -303,7 +303,7 @@ func (s *Server) UpdateEntity(ctx context.Context, req *pb.UpdateEntityRequest) func (s *Server) DeleteEntity(ctx context.Context, req *pb.EntityId) (*pb.Empty, error) { log.Printf("[server.DeleteEntity] Deleting Entity metadata: %s", req.Id) - // Check if entity exists before deleting + // Check if metadata exists before deleting _, err := s.mongoRepo.ReadMetadata(ctx, req.Id) if err != nil { // NOTE: Not returning an error here because we want to delete the diff --git a/opengin/core-api/db/repository/mongo/mongodb_client_test.go b/opengin/core-api/db/repository/mongo/mongodb_client_test.go index 36caae76..3f60d62a 100644 --- a/opengin/core-api/db/repository/mongo/mongodb_client_test.go +++ b/opengin/core-api/db/repository/mongo/mongodb_client_test.go @@ -67,13 +67,13 @@ func TestMain(m *testing.M) { os.Exit(exitCode) } -// TestCreateAndReadEntity verifies the entity creation and reading functionality: -// 1. Creates an entity with test metadata -// 2. Confirms the entity exists in the database after creation -// 3. Reads the entity and verifies the metadata values -// 4. Validates that the entity ID is correctly set +// TestCreateAndReadMetadata verifies the metadata creation and reading functionality: +// 1. Creates a metadata document with test values +// 2. Confirms the metadata exists in the database after creation +// 3. Reads the metadata and verifies the values +// 4. Validates that the document ID (entity ID) is correctly set // 5. Confirms the metadata values are stored correctly -func TestCreateAndReadEntity(t *testing.T) { +func TestCreateAndReadMetadata(t *testing.T) { // Log database and collection information log.Printf("Test using database: %s, collection: %s", testRepo.GetDBName(), testRepo.GetCollectionName()) @@ -119,14 +119,13 @@ func TestCreateAndReadEntity(t *testing.T) { assert.Contains(t, readEntity.Metadata, "key2") } -// TestUpdateEntityMetadata verifies the metadata update functionality: -// 1. Creates an entity with initial metadata +// TestUpdateMetadata verifies the metadata update functionality: +// 1. Creates initial metadata for a document // 2. Updates the metadata with new values -// 3. Reads the updated entity and verifies the metadata changes +// 3. Reads the updated metadata and verifies the changes // 4. Confirms that the metadata values are updated correctly -// 5. Validates that the entity ID remains unchanged -// TestUpdateEntityMetadata tests updating entity metadata -func TestUpdateEntityMetadata(t *testing.T) { +// 5. Validates that the document ID remains unchanged +func TestUpdateMetadata(t *testing.T) { // Log database and collection information log.Printf("Test using database: %s, collection: %s", testRepo.GetDBName(), testRepo.GetCollectionName()) @@ -174,14 +173,14 @@ func TestUpdateEntityMetadata(t *testing.T) { assert.Contains(t, readEntity.Metadata, "key3") } -// TestDeleteEntity verifies the entity deletion functionality: -// 1. Creates an entity with test metadata -// 2. Confirms the entity exists in the database after creation -// 3. Tests the DeleteEntity method by removing the entity +// TestDeleteMetadata verifies the metadata deletion functionality: +// 1. Creates a metadata document with test values +// 2. Confirms the metadata exists in the database after creation +// 3. Tests the DeleteMetadata method by removing the document // 4. Verifies that exactly one document was deleted (DeletedCount = 1) -// 5. Confirms the entity no longer exists by attempting to read it -// 6. Validates that an error is returned when trying to read a deleted entity -func TestDeleteEntity(t *testing.T) { +// 5. Confirms the metadata no longer exists by attempting to read it +// 6. Validates that an error is returned when trying to read deleted metadata +func TestDeleteMetadata(t *testing.T) { // Log database and collection information log.Printf("Test using database: %s, collection: %s", testRepo.GetDBName(), testRepo.GetCollectionName())