From b347f79625fef4a9f3c8dc82ca90c5e70d6ef6d1 Mon Sep 17 00:00:00 2001 From: Marco Metz Date: Tue, 23 Feb 2021 11:02:12 +0100 Subject: [PATCH] Sortierung nach PublishedAt integriert --- app/graphql/resolvers/generic_item_search.rb | 10 ++++++++++ app/models/data_resources/news_item.rb | 6 +++--- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/app/graphql/resolvers/generic_item_search.rb b/app/graphql/resolvers/generic_item_search.rb index bc986d2f..7fe5f19a 100644 --- a/app/graphql/resolvers/generic_item_search.rb +++ b/app/graphql/resolvers/generic_item_search.rb @@ -11,6 +11,8 @@ class Resolvers::GenericItemSearch type types[Types::QueryTypes::GenericItemType] class GenericItemOrder < ::Types::BaseEnum + value "publishedAt_ASC" + value "publishedAt_DESC" value "createdAt_ASC" value "createdAt_DESC" value "updatedAt_ASC" @@ -40,6 +42,14 @@ def apply_order(scope, value) scope.order(value) end + def apply_order_with_published_at_desc(scope) + scope.order("published_at DESC") + end + + def apply_order_with_published_at_asc(scope) + scope.order("published_at ASC") + end + def apply_order_with_created_at_desc(scope) scope.order("created_at DESC") end diff --git a/app/models/data_resources/news_item.rb b/app/models/data_resources/news_item.rb index 02918120..6a21e94c 100644 --- a/app/models/data_resources/news_item.rb +++ b/app/models/data_resources/news_item.rb @@ -15,12 +15,12 @@ class NewsItem < ApplicationRecord belongs_to :data_provider + has_one :address, as: :addressable, dependent: :destroy + has_one :external_reference, as: :external, dependent: :destroy + has_one :source_url, as: :web_urlable, class_name: "WebUrl", dependent: :destroy has_many :data_resource_categories, as: :data_resource has_many :categories, through: :data_resource_categories has_many :content_blocks, as: :content_blockable, dependent: :destroy - has_one :external_reference, as: :external, dependent: :destroy - has_one :address, as: :addressable, dependent: :destroy - has_one :source_url, as: :web_urlable, class_name: "WebUrl", dependent: :destroy scope :with_category, lambda { |category_id| where(categories: { id: category_id }).joins(:categories)