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:
@@ -155,6 +155,12 @@ func (h *MediaHandler) DownloadBook(c *echo.Context) error {
|
|||||||
return nil
|
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 {
|
type AddToShelfRequest struct {
|
||||||
MediaItemIDs []string `json:"media_item_ids" validate:"required"`
|
MediaItemIDs []string `json:"media_item_ids" validate:"required"`
|
||||||
ShelfName string `json:"shelf_name"`
|
ShelfName string `json:"shelf_name"`
|
||||||
@@ -1450,13 +1456,12 @@ func (mh *MediaHandler) SearchMediaItems(c *echo.Context) error {
|
|||||||
"library_id_uuid", libUUID.Valid,
|
"library_id_uuid", libUUID.Valid,
|
||||||
"library_id_bytes", libUUID.Bytes)
|
"library_id_bytes", libUUID.Bytes)
|
||||||
|
|
||||||
// Call SearchService instead of DB directly
|
// Call shared search service
|
||||||
results, err := mh.searchService.SearchMediaItemsUnified(c.Request().Context(), params)
|
results, _, err := mh.searchService.ExecuteSearch(c.Request().Context(), params)
|
||||||
if err != nil && err != pgx.ErrNoRows {
|
if err != nil {
|
||||||
c.Logger().Error("search error", "error", err.Error())
|
c.Logger().Error("search error", "error", err.Error())
|
||||||
return c.JSON(http.StatusInternalServerError, map[string]string{"error": err.Error()})
|
return c.JSON(http.StatusInternalServerError, map[string]string{"error": err.Error()})
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(results) == 0 {
|
if len(results) == 0 {
|
||||||
return c.JSON(http.StatusNotFound, map[string]interface{}{
|
return c.JSON(http.StatusNotFound, map[string]interface{}{
|
||||||
"error": "no results found",
|
"error": "no results found",
|
||||||
@@ -1464,7 +1469,6 @@ func (mh *MediaHandler) SearchMediaItems(c *echo.Context) error {
|
|||||||
"results": []interface{}{},
|
"results": []interface{}{},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
return c.JSON(http.StatusOK, results)
|
return c.JSON(http.StatusOK, results)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user