Skip to content

Commit

Permalink
Sortierung nach PublishedAt integriert
Browse files Browse the repository at this point in the history
  • Loading branch information
marcometz committed Feb 23, 2021
1 parent d4c4f6a commit b347f79
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
10 changes: 10 additions & 0 deletions app/graphql/resolvers/generic_item_search.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ class Resolvers::GenericItemSearch
type types[Types::QueryTypes::GenericItemType]

class GenericItemOrder < ::Types::BaseEnum
value "publishedAt_ASC"
value "publishedAt_DESC"

This comment was marked as resolved.

Copy link
@donni106

donni106 Feb 24, 2021

Member

hier ist es jetzt oben, bei news aber vor id

class NewsItemsOrder < ::Types::BaseEnum
  value "createdAt_ASC"
  value "createdAt_DESC"
  value "updatedAt_ASC"
  value "updatedAt_DESC"
  value "publishedAt_ASC"
  value "publishedAt_DESC"
  value "id_ASC"
  value "id_DESC"
end

es hilft, wenn sowas gleich gehalten wird beim lesen von code und vergleich von klassen.

value "createdAt_ASC"
value "createdAt_DESC"
value "updatedAt_ASC"
Expand Down Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions app/models/data_resources/news_item.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit b347f79

Please sign in to comment.