make it work better

This commit is contained in:
Donovan Daniels 2024-10-08 07:39:28 -05:00
parent 8dbe779237
commit aa1928303d
Signed by: Donovan_DMC
GPG Key ID: 907D29CBFD6157BA
2 changed files with 6 additions and 2 deletions

View File

@ -69,7 +69,7 @@ module YiffRest
end end
def search_images_params def search_images_params
permit_search_params(%i[category md5 original_url artists]) permit_search_params(%i[category md5 original_url artist])
end end
def create_params def create_params

View File

@ -75,11 +75,15 @@ class APIImage < ApplicationRecord
data data
end end
def artists_like(name)
where(id: APIImage.from("unnest(artists) AS artist").where("artist LIKE ?", name.to_escaped_for_sql_like))
end
def search(params) def search(params)
q = super q = super
q = q.attribute_matches(:category, params[:category]) q = q.attribute_matches(:category, params[:category])
q = q.attribute_matches(:original_url, params[:original_url]) q = q.attribute_matches(:original_url, params[:original_url])
q = q.attribute_matches(:artists, params[:artists]) q = q.artists_like(params[:artist]) if params[:artist].present?
q.order(created_at: :desc) q.order(created_at: :desc)
end end
end end