Skip to content

Commit

Permalink
Merge pull request #3133 from gravitl/NET-1613-nodes
Browse files Browse the repository at this point in the history
fix tag udpate with new ID
  • Loading branch information
abhishek9686 authored Sep 22, 2024
2 parents 5e385c8 + ad4c663 commit f1a1ab5
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
2 changes: 2 additions & 0 deletions controllers/tags.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,8 @@ func updateTag(w http.ResponseWriter, r *http.Request) {
logic.ReturnErrorResponse(w, r, logic.FormatError(err, "badrequest"))
return
}
// delete old Tag entry
logic.DeleteTag(updateTag.ID)
}
go logic.UpdateTag(updateTag, newID)
logic.ReturnSuccessResponse(w, r, "updating tags")
Expand Down
14 changes: 12 additions & 2 deletions logic/tags.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ var tagMutex = &sync.RWMutex{}
// GetTag - fetches tag info
func GetTag(tagID models.TagID) (models.Tag, error) {
data, err := database.FetchRecord(database.TAG_TABLE_NAME, tagID.String())
if err != nil && !database.IsEmptyRecord(err) {
if err != nil {
return models.Tag{}, err
}
tag := models.Tag{}
Expand Down Expand Up @@ -137,11 +137,21 @@ func UpdateTag(req models.UpdateTagReq, newID models.TagID) {
if node.Tags == nil {
node.Tags = make(map[models.TagID]struct{})
}
node.Tags[req.ID] = struct{}{}
if newID != "" {
node.Tags[newID] = struct{}{}
} else {
node.Tags[req.ID] = struct{}{}
}
UpsertNode(&node)
} else {
if newID != "" {
delete(node.Tags, req.ID)
node.Tags[newID] = struct{}{}
UpsertNode(&node)
}
delete(tagNodesMap, node.ID.String())
}

}
for _, deletedTaggedNode := range tagNodesMap {
deletedTaggedHost := deletedTaggedNode
Expand Down

0 comments on commit f1a1ab5

Please sign in to comment.