Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix tag udpate with new ID #3133

Merged
merged 1 commit into from
Sep 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading