Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions app/models/content.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ class Content < ApplicationRecord
has_many :user_contents, dependent: :destroy
has_many :users, through: :user_contents
has_many :line_flags, dependent: :destroy
has_many :line_notifications
belongs_to :master

enum stream: { default: 0, Mon: 1, Tue: 2, Wed: 3, Thu: 4, Fri: 5, Sat: 6, Sun: 7 }
Expand Down Expand Up @@ -36,4 +37,12 @@ def line_on
def line_off
update(line_flag: false)
end

def self.total_line_notification
all.sum(:line_notifications_count)
end

def self.reset_counter
update_all(line_notifications_count: 0)
end
end
8 changes: 4 additions & 4 deletions app/models/line_notification.rb
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
class LineNotification < ApplicationRecord
belongs_to :master
counter_culture :master
belongs_to :content
counter_culture :content

scope :monthly_total, -> { where(month: Date.today.month) }

def self.can_notify?
monthly_total.size < 1000
end

def self.create_record(master, month)
create(master_id: master.id, month: month)
def self.create_record(content, month)
create(content_id: content.id, month: month)
end
end
2 changes: 1 addition & 1 deletion db/migrate/20220106041056_create_line_notifications.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
class CreateLineNotifications < ActiveRecord::Migration[5.2]
def change
create_table :line_notifications do |t|
t.references :master, foreign_key: true
t.references :content, foreign_key: true
t.integer :month, null: false
t.timestamps
end
Expand Down

This file was deleted.

13 changes: 13 additions & 0 deletions db/migrate/20220125023304_add_content_to_master_colmuns.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
class AddContentToMasterColmuns < ActiveRecord::Migration[5.2]
def up
add_column :contents, :season, :string
add_column :contents, :dummy_episode, :integer, default: 0
add_column :contents, :update_day, :string
end

def down
remove_column :contents, :season, :string
remove_column :contents, :dummy_episode, :integer, default: 0
remove_column :contents, :update_day, :string
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class AddLineNotificationsCountToContents < ActiveRecord::Migration[5.2]
def self.up
add_column :contents, :line_notifications_count, :integer, null: false, default: 0
end

def self.down
remove_column :contents, :line_notifications_count
end
end
11 changes: 7 additions & 4 deletions db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 2022_01_18_131731) do
ActiveRecord::Schema.define(version: 2022_01_25_025052) do

create_table "contents", force: :cascade do |t|
t.string "title", null: false
Expand All @@ -24,6 +24,10 @@
t.integer "episode", default: 0
t.boolean "line_flag", default: false, null: false
t.integer "media", default: 0, null: false
t.string "season"
t.integer "dummy_episode", default: 0
t.string "update_day"
t.integer "line_notifications_count", default: 0, null: false
end

create_table "line_flags", force: :cascade do |t|
Expand All @@ -36,11 +40,11 @@
end

create_table "line_notifications", force: :cascade do |t|
t.integer "master_id"
t.integer "content_id"
t.integer "month", null: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["master_id"], name: "index_line_notifications_on_master_id"
t.index ["content_id"], name: "index_line_notifications_on_content_id"
end

create_table "masters", force: :cascade do |t|
Expand All @@ -53,7 +57,6 @@
t.integer "episode", default: 0
t.string "season"
t.string "update_day"
t.integer "line_notifications_count", default: 0, null: false
t.integer "dummy_episode", default: 0
t.integer "media", default: 0, null: false
end
Expand Down
6 changes: 3 additions & 3 deletions lib/tasks/reset_counter.rake
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ namespace :reset_counter do
task line_notifications: :environment do
include Day
if first_day?
p "#{last_month}のLINE通知数は#{Master.total_line_notification}件でした"
Master.reset_counter
p "#{last_month}のLINE通知数は#{Content.total_line_notification}件でした"
Content.reset_counter
p "LINE通知数をリセットしました"
else
p "#{yesterday}時点のLINE通知数は#{Master.total_line_notification}件です"
p "#{yesterday}時点のLINE通知数は#{Content.total_line_notification}件です"
end
end
end