From a33d5214926f890afec8b22c56597e0ae0d30b53 Mon Sep 17 00:00:00 2001 From: John O'Keefe Date: Fri, 27 Mar 2026 14:50:21 -0400 Subject: [PATCH] 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 --- internal/services/search.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/internal/services/search.go b/internal/services/search.go index 9f2aa22..2e41fba 100644 --- a/internal/services/search.go +++ b/internal/services/search.go @@ -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 +}