add search by terms on posts
This commit is contained in:
@@ -29,7 +29,7 @@ class PostsController < ApplicationController
|
||||
private
|
||||
|
||||
def query_params
|
||||
params.permit(:scope) || {}
|
||||
params.permit(:scope, :terms)
|
||||
end
|
||||
|
||||
def post_params
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
class Post < ApplicationRecord
|
||||
include PgSearch::Model
|
||||
|
||||
belongs_to :user
|
||||
belongs_to :quoted_post, optional: true, class_name: 'Post'
|
||||
|
||||
validates :content, length: { maximum: 777 }
|
||||
validates :content, presence: true, unless: :repost?
|
||||
|
||||
validate :user, :limit_of_post_per_day
|
||||
|
||||
scope :by_user_follows, ->(user) {
|
||||
where(user_id: user.following_ids)
|
||||
}
|
||||
pg_search_scope :by_terms, against: :content
|
||||
scope :by_user_follows, ->(user) { where(user_id: user.following_ids) }
|
||||
|
||||
def repost?
|
||||
kind == :quoted_post
|
||||
|
||||
@@ -17,6 +17,10 @@ class PostsQueryResolverService
|
||||
scope = scope.by_user_follows(current_user)
|
||||
end
|
||||
|
||||
if filter[:terms]
|
||||
scope = scope.by_terms(filter[:terms])
|
||||
end
|
||||
|
||||
scope
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user