Skip to content

Commit

Permalink
Merge pull request #205 from ZeusWPI/recent_beverages
Browse files Browse the repository at this point in the history
add recent beverages endpoint
  • Loading branch information
Topvennie authored Aug 9, 2024
2 parents d1c2d58 + 34ed920 commit 25a5a60
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 3 deletions.
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,10 @@ To provide a consistent experience on every system, docker and docker-compose is
1. Install [asdf](http://asdf-vm.com/guide/getting-started.html#getting-started)
2. Install dependencies: `asdf install`
3. Install gems: `bundle install`
4. Migrate the db using `bundle exec rails db:migrate`
5. Seed the db using `bundle exec rails db:seed`
6. Start Tap by running `bundle exec rails s`
4. Run: `yarn`
5. Migrate the db using `bundle exec rails db:migrate`
6. Seed the db using `bundle exec rails db:seed`
7. Start Tap by running `bundle exec rails s`

## Production

Expand Down
26 changes: 26 additions & 0 deletions app/controllers/public_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# frozen_string_literal: true

class PublicController < ApplicationController
include ApplicationHelper
include OrderSessionHelper

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

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
{
order_id: order.id,
order_created_at: order.created_at,
product_name: product.name,
product_category: product.category
}
end
end.flatten

render json: { orders: mapped_orders }
end
end
2 changes: 2 additions & 0 deletions app/models/order.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ 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 :recent, -> { where(created_at: 2.weeks.ago..Time.zone.now) }

def to_sentence
order_items.map do |oi|
pluralize(oi.count, oi.product.name)
Expand Down
2 changes: 2 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@
# Koelkast overview page
get "overview" => "orders#overview", as: "orders"

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

# Guest endpoints
namespace :guest do
resources :orders, only: [:new, :create]
Expand Down

0 comments on commit 25a5a60

Please sign in to comment.