feat(media): add ExecuteSearch wrapper and update SearchMediaItems

Add public ExecuteSearch method to MediaHandler that delegates to SearchService. Update SearchMediaItems to use the new shared service method instead of calling SearchMediaItemsUnified directly.

- Add ExecuteSearch wrapper method (line 160-162)
- Update SearchMediaItems to use searchService.ExecuteSearch
- Maintains existing JSON API behavior while enabling shared logic
This commit is contained in:
2026-03-27 14:50:28 -04:00
parent a33d521492
commit b1446f15f8
+9 -5
View File
@@ -155,6 +155,12 @@ func (h *MediaHandler) DownloadBook(c *echo.Context) error {
return nil
}
// ExecuteSearch performs search and returns results with count
// Public wrapper for shared search logic used by both JSON and HTML endpoints
func (h *MediaHandler) ExecuteSearch(ctx context.Context, params services.SearchParams) ([]database.SearchMediaItemsUnifiedRow, int, error) {
return h.searchService.ExecuteSearch(ctx, params)
}
type AddToShelfRequest struct {
MediaItemIDs []string `json:"media_item_ids" validate:"required"`
ShelfName string `json:"shelf_name"`
@@ -1450,13 +1456,12 @@ func (mh *MediaHandler) SearchMediaItems(c *echo.Context) error {
"library_id_uuid", libUUID.Valid,
"library_id_bytes", libUUID.Bytes)
// Call SearchService instead of DB directly
results, err := mh.searchService.SearchMediaItemsUnified(c.Request().Context(), params)
if err != nil && err != pgx.ErrNoRows {
// Call shared search service
results, _, err := mh.searchService.ExecuteSearch(c.Request().Context(), params)
if err != nil {
c.Logger().Error("search error", "error", err.Error())
return c.JSON(http.StatusInternalServerError, map[string]string{"error": err.Error()})
}
if len(results) == 0 {
return c.JSON(http.StatusNotFound, map[string]interface{}{
"error": "no results found",
@@ -1464,7 +1469,6 @@ func (mh *MediaHandler) SearchMediaItems(c *echo.Context) error {
"results": []interface{}{},
})
}
return c.JSON(http.StatusOK, results)
}