mirror of
https://github.com/icereed/paperless-gpt.git
synced 2025-03-13 13:18:02 -05:00
feat: enhance tag management by preserving previous tags and removing duplicates (#119)
Closes #90
This commit is contained in:
parent
e144661dfb
commit
c1104449dd
2 changed files with 17 additions and 5 deletions
|
@ -283,6 +283,12 @@ func (c *PaperlessClient) UpdateDocuments(ctx context.Context, documents []Docum
|
||||||
originalFields["tags"] = originalTags
|
originalFields["tags"] = originalTags
|
||||||
// remove autoTag to prevent infinite loop - this is required in case of undo
|
// remove autoTag to prevent infinite loop - this is required in case of undo
|
||||||
tags = removeTagFromList(tags, autoTag)
|
tags = removeTagFromList(tags, autoTag)
|
||||||
|
|
||||||
|
// keep previous tags
|
||||||
|
tags = append(tags, originalTags...)
|
||||||
|
// remove duplicates
|
||||||
|
slices.Sort(tags)
|
||||||
|
tags = slices.Compact(tags)
|
||||||
}
|
}
|
||||||
|
|
||||||
updatedTagsJSON, err := json.Marshal(tags)
|
updatedTagsJSON, err := json.Marshal(tags)
|
||||||
|
|
|
@ -300,18 +300,24 @@ func TestUpdateDocuments(t *testing.T) {
|
||||||
OriginalDocument: Document{
|
OriginalDocument: Document{
|
||||||
ID: 1,
|
ID: 1,
|
||||||
Title: "Old Title",
|
Title: "Old Title",
|
||||||
Tags: []string{"tag1"},
|
Tags: []string{"tag1", "tag3", "manual", "removeMe"},
|
||||||
},
|
},
|
||||||
SuggestedTitle: "New Title",
|
SuggestedTitle: "New Title",
|
||||||
SuggestedTags: []string{"tag2"},
|
SuggestedTags: []string{"tag2", "tag3"},
|
||||||
|
RemoveTags: []string{"removeMe"},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
idTag1 := 1
|
||||||
|
idTag2 := 2
|
||||||
|
idTag3 := 4
|
||||||
// Mock data for tags
|
// Mock data for tags
|
||||||
tagsResponse := map[string]interface{}{
|
tagsResponse := map[string]interface{}{
|
||||||
"results": []map[string]interface{}{
|
"results": []map[string]interface{}{
|
||||||
{"id": 1, "name": "tag1"},
|
{"id": idTag1, "name": "tag1"},
|
||||||
{"id": 2, "name": "tag2"},
|
{"id": idTag2, "name": "tag2"},
|
||||||
{"id": 3, "name": "manual"},
|
{"id": 3, "name": "manual"},
|
||||||
|
{"id": idTag3, "name": "tag3"},
|
||||||
|
{"id": 5, "name": "removeMe"},
|
||||||
},
|
},
|
||||||
"next": nil,
|
"next": nil,
|
||||||
}
|
}
|
||||||
|
@ -342,7 +348,7 @@ func TestUpdateDocuments(t *testing.T) {
|
||||||
// Expected updated fields
|
// Expected updated fields
|
||||||
expectedFields := map[string]interface{}{
|
expectedFields := map[string]interface{}{
|
||||||
"title": "New Title",
|
"title": "New Title",
|
||||||
"tags": []interface{}{float64(2)}, // tag2 ID
|
"tags": []interface{}{float64(idTag1), float64(idTag2), float64(idTag3)}, // keep also previous tags
|
||||||
}
|
}
|
||||||
|
|
||||||
assert.Equal(t, expectedFields, updatedFields)
|
assert.Equal(t, expectedFields, updatedFields)
|
||||||
|
|
Loading…
Reference in a new issue