Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Discordのmentorチャンネルに提出物の溜まり具合を定期的に投稿する #2568

Merged
12 changes: 12 additions & 0 deletions app/controllers/api/products/passed_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# frozen_string_literal: true

class API::Products::PassedController < API::BaseController
def show
products = Product
.not_responded_products
.list
@passed5 = products.count { |product| product.elapsed_days == 5 }
@passed6 = products.count { |product| product.elapsed_days == 6 }
@over7 = products.count { |product| product.elapsed_days >= 7 }
end
end
10 changes: 7 additions & 3 deletions app/models/product.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class Product < ApplicationRecord
scope :reorder_for_not_responded_products, -> { reorder(published_at: :desc, id: :desc) }

# rubocop:disable Metrics/MethodLength
def self.not_responded_products
def self.not_responded_product_ids
sql = <<~SQL
WITH last_comments AS (
SELECT *
Expand All @@ -69,8 +69,12 @@ def self.not_responded_products
OR unchecked_products.user_id = last_comments.user_id
ORDER BY unchecked_products.created_at DESC
SQL
product_ids = Product.find_by_sql(sql).map(&:id)
Product.where(id: product_ids).order(created_at: :desc)
Product.find_by_sql(sql).map(&:id)
end

def self.not_responded_products
Product.where(id: not_responded_product_ids)
.order(created_at: :desc)
end
# rubocop:enable Metrics/MethodLength

Expand Down
19 changes: 19 additions & 0 deletions app/views/api/products/passed/show.text.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<% if @passed5 + @passed6 + @over7 > 0 %>
提出されてから日数が経っている提出物の数をお知らせします。

<% if @passed5 > 0 %>
- 5日経過:<%= @passed5 %>件
<% end %>
<% if @passed6 > 0 %>
- 6日経過:<%= @passed6 %>件
<% end %>
<% if @over7 > 0 %>
- 7日以上経過:<%= @over7 %>件
<% end %>

未返信の提出物一覧:
https://bootcamp.fjord.jp/products/not_responded
<% else %>
提出されたから5日以上経過している提出物はありません。
メンターの皆様、日々の提出物の確認ありがとうございます。
<% end %>
3 changes: 2 additions & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@
resources :unchecked, only: %i(index)
resources :not_responded, only: %i(index)
resources :self_assigned, only: %i(index)
resource :checker, only: %i(update), controller: "checker"
resource :checker, only: %i(update), controller: 'checker'
resource :passed, only: %i(show), controller: 'passed'
end
resources :products, only: %i(index)
namespace :categories_practices do
Expand Down
Loading