Skip to content

Commit

Permalink
generalize to 'recent'
Browse files Browse the repository at this point in the history
  • Loading branch information
Topvennie committed Aug 9, 2024
1 parent faaa148 commit 34ed920
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 8 deletions.
8 changes: 4 additions & 4 deletions app/controllers/public_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ class PublicController < ApplicationController
include ApplicationHelper
include OrderSessionHelper

skip_before_action :authenticate_user_from_token!, only: :recent_beverages
skip_before_action :authenticate_user!, only: :recent_beverages
skip_before_action :authenticate_user_from_token!, only: :recent
skip_before_action :authenticate_user!, only: :recent

def recent_beverages
orders = Order.recent_beverages
def recent
orders = Order.recent
mapped_orders = orders.joins(:order_items => :product).map do |order|
order.order_items.map do |order_item|
product = order_item.product
Expand Down
4 changes: 1 addition & 3 deletions app/models/order.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,7 @@ class Order < ApplicationRecord
scope :pending, -> { where(created_at: Rails.application.config.call_api_after.ago..) }
scope :final, -> { where(created_at: ..Rails.application.config.call_api_after.ago) }

scope :from_last_two_weeks, -> { where(created_at: 2.weeks.ago..Time.zone.now) }
scope :with_category, ->(category) { joins(:products).where(products: { category: category }).distinct }
scope :recent_beverages, -> { from_last_two_weeks.with_category("beverages") }
scope :recent, -> { where(created_at: 2.weeks.ago..Time.zone.now) }

def to_sentence
order_items.map do |oi|
Expand Down
2 changes: 1 addition & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
# Koelkast overview page
get "overview" => "orders#overview", as: "orders"

get "recent_beverages" => "public#recent_beverages", as: "recent_beverages"
get "recent" => "public#recent", as: "recent"

# Guest endpoints
namespace :guest do
Expand Down

0 comments on commit 34ed920

Please sign in to comment.