feat(search): add ExecuteSearch method to SearchService

Add shared search method that returns results with count. This method will be used by both JSON API endpoints and HTML rendering for HTMX, avoiding duplicate business logic.

- Extracts common search logic into reusable service method
- Returns search results with total count for pagination
- Follows DRY principle by eliminating duplicated search code
This commit is contained in:
2026-03-27 14:50:21 -04:00
parent d8c63b8b8e
commit a33d521492
+13
View File
@@ -5,6 +5,7 @@ import (
"context"
"strings"
"github.com/jackc/pgx/v5"
"github.com/jackc/pgx/v5/pgtype"
)
@@ -208,3 +209,15 @@ func (s *SearchService) SearchFieldValues(ctx context.Context, params FieldSearc
return []FieldValue{}, nil
}
}
// ExecuteSearch performs search and returns results with count
// Shared between JSON endpoint and HTML rendering
func (s *SearchService) ExecuteSearch(ctx context.Context, params SearchParams) ([]database.SearchMediaItemsUnifiedRow, int, error) {
results, err := s.SearchMediaItemsUnified(ctx, params)
if err != nil && err != pgx.ErrNoRows {
return nil, 0, err
}
count := len(results)
return results, count, nil
}