Files
postter/app/services/posts_query_resolver_service.rb
João Victor Geonizeli a08a889e7d add search by terms on posts
2022-02-28 13:45:28 -03:00

26 lines
488 B
Ruby

class PostsQueryResolverService
attr_reader :filter, :current_user
def initialize(filter, current_user)
@filter = filter
@current_user = current_user
end
def self.call(filter, current_user)
new(filter, current_user).call
end
def call
scope = Post.all
if filter[:scope] == 'follows' && current_user
scope = scope.by_user_follows(current_user)
end
if filter[:terms]
scope = scope.by_terms(filter[:terms])
end
scope
end
end