Tag query change (#44)

* Tag query change

---------

Co-authored-by: Icereed <domi@icereed.net>
This commit is contained in:
ccrlawrence 2024-11-11 09:40:39 +00:00 committed by GitHub
parent 6d4683c9a3
commit d1f23de5a6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 4 additions and 4 deletions

View file

@ -108,10 +108,10 @@ func (c *PaperlessClient) GetAllTags(ctx context.Context) (map[string]int, error
func (c *PaperlessClient) GetDocumentsByTags(ctx context.Context, tags []string) ([]Document, error) {
tagQueries := make([]string, len(tags))
for i, tag := range tags {
tagQueries[i] = fmt.Sprintf("tag:%s", tag)
tagQueries[i] = fmt.Sprintf("tags__name__iexact=%s", tag)
}
searchQuery := strings.Join(tagQueries, " ")
path := fmt.Sprintf("api/documents/?query=%s", urlEncode(searchQuery))
searchQuery := strings.Join(tagQueries, "&")
path := fmt.Sprintf("api/documents/?%s", urlEncode(searchQuery))
resp, err := c.Do(ctx, "GET", path, nil)
if err != nil {

View file

@ -203,7 +203,7 @@ func TestGetDocumentsByTags(t *testing.T) {
// Set mock responses
env.setMockResponse("/api/documents/", func(w http.ResponseWriter, r *http.Request) {
// Verify query parameters
expectedQuery := "query=tag:tag1+tag:tag2"
expectedQuery := "tags__name__iexact=tag1&tags__name__iexact=tag2"
assert.Equal(t, expectedQuery, r.URL.RawQuery)
w.WriteHeader(http.StatusOK)
json.NewEncoder(w).Encode(documentsResponse)