Add more search options for image ui

This commit is contained in:
Donovan Daniels 2024-05-07 01:57:00 -05:00
parent b1c702e3cd
commit ad3af75287
Signed by: Donovan_DMC
GPG Key ID: 907D29CBFD6157BA
3 changed files with 12 additions and 3 deletions

View File

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

View File

@ -67,6 +67,14 @@ class APIImage < ApplicationRecord
end end
data data
end end
def search(params)
q = super
params[:id] ||= params[:md5]
q = q.attribute_matches(:category, params[:category])
q = q.attribute_matches(:original_url, params[:original_url])
q.order(created_at: :desc)
end
end end
extend SearchMethods extend SearchMethods

View File

@ -58,8 +58,10 @@ class ApplicationRecord < ActiveRecord::Base
numeric_attribute_matches(attribute, value, **) numeric_attribute_matches(attribute, value, **)
when :string, :text when :string, :text
text_attribute_matches(attribute, value, **) text_attribute_matches(attribute, value, **)
when :uuid
where(attribute => value)
else else
raise(ArgumentError, "unhandled attribute type") raise(ArgumentError, "unhandled attribute type: #{column.sql_type_metadata.type}")
end end
end end
@ -143,7 +145,6 @@ class ApplicationRecord < ActiveRecord::Base
q = all q = all
q = q.attribute_matches(:id, params[:id]) q = q.attribute_matches(:id, params[:id])
q = q.attribute_matches(:category, params[:category])
q = q.attribute_matches(:created_at, params[:created_at]) if attribute_names.include?("created_at") q = q.attribute_matches(:created_at, params[:created_at]) if attribute_names.include?("created_at")
q = q.attribute_matches(:updated_at, params[:updated_at]) if attribute_names.include?("updated_at") q = q.attribute_matches(:updated_at, params[:updated_at]) if attribute_names.include?("updated_at")