From 1fb130407e5dc2a0763952f835a42e9db741f1c4 Mon Sep 17 00:00:00 2001 From: Shubham Prajapati Date: Thu, 13 Jun 2024 11:48:28 +0530 Subject: [PATCH] Updating it to peer_id --- api/v1/client/client.go | 2 +- api/v1/nodes/testNode.go | 2 +- app/p2p-Node/service/service.go | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/api/v1/client/client.go b/api/v1/client/client.go index 22cc8cc..c7d92ac 100644 --- a/api/v1/client/client.go +++ b/api/v1/client/client.go @@ -46,7 +46,7 @@ func RegisterClient(c *gin.Context) { // return // } var node *models.Node - if err := db.Model(&models.Node{}).Where("id = ?", region_id).First(&node).Error; err != nil { + if err := db.Model(&models.Node{}).Where("peer_id = ?", region_id).First(&node).Error; err != nil { logwrapper.Errorf("failed to get node: %s", err) httpo.NewErrorResponse(http.StatusBadRequest, err.Error()).SendD(c) return diff --git a/api/v1/nodes/testNode.go b/api/v1/nodes/testNode.go index c9788be..a9ff4bc 100644 --- a/api/v1/nodes/testNode.go +++ b/api/v1/nodes/testNode.go @@ -92,7 +92,7 @@ func UpdateNode(node *models.Node) error { // DeleteNode deletes a node record from the database func DeleteNode(id string) error { DB := dbconfig.GetDb() - return DB.Delete(&models.Node{}, id).Error + return DB.Delete(&models.Node{}, "where peer_id = ?",id).Error } func getRandomString(n int) string { diff --git a/app/p2p-Node/service/service.go b/app/p2p-Node/service/service.go index b87a261..9c74328 100644 --- a/app/p2p-Node/service/service.go +++ b/app/p2p-Node/service/service.go @@ -108,7 +108,7 @@ func SubscribeTopics(ps *pubsub.PubSub, h host.Host, ctx context.Context) { func CreateOrUpdate(db *gorm.DB, node *models.Node) error { var model models.Node - result := db.Model(&models.Node{}).Where("id = ?", node.PeerId) + result := db.Model(&models.Node{}).Where("peer_id = ?", node.PeerId) if result.RowsAffected != 0 { //exists, update return db.Model(&model).Updates(node).Error