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

mentor_last_comment_at を mentor_last_commented_at に変更 #3549

Merged
merged 4 commits into from
Nov 15, 2021
Merged
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
22 changes: 12 additions & 10 deletions app/javascript/product.vue
Original file line number Diff line number Diff line change
Expand Up @@ -70,30 +70,32 @@
)

.thread-list-item-meta__item(
v-if='product.self_last_comment_at_date_time && product.mentor_last_comment_at_date_time'
v-if='product.self_last_commented_at_date_time && product.mentor_last_commented_at_date_time'
)
time.a-meta(
v-if='product.self_last_comment_at_date_time > product.mentor_last_comment_at_date_time'
v-if='product.self_last_commented_at_date_time > product.mentor_last_commented_at_date_time'
)
| 〜 {{ product.self_last_comment_at }}(
| 〜 {{ product.self_last_commented_at }}(
strong
| 提出者
| )
time.a-meta(
v-if='product.self_last_comment_at_date_time < product.mentor_last_comment_at_date_time'
v-if='product.self_last_commented_at_date_time < product.mentor_last_commented_at_date_time'
)
| 〜 {{ product.mentor_last_comment_at }}(メンター)
| 〜 {{ product.mentor_last_commented_at }}(メンター)

.thread-list-item-meta__item(
v-else-if='product.self_last_comment_at_date_time || product.mentor_last_comment_at_date_time'
v-else-if='product.self_last_commented_at_date_time || product.mentor_last_commented_at_date_time'
)
time.a-meta(v-if='product.self_last_comment_at_date_time')
| 〜 {{ product.self_last_comment_at }}(
time.a-meta(v-if='product.self_last_commented_at_date_time')
| 〜 {{ product.self_last_commented_at }}(
strong
| 提出者
| )
time.a-meta(v-else-if='product.mentor_last_comment_at_date_time')
| 〜 {{ product.mentor_last_comment_at }}(メンター)
time.a-meta(
v-else-if='product.mentor_last_commented_at_date_time'
)
| 〜 {{ product.mentor_last_commented_at }}(メンター)

.stamp.stamp-approve(v-if='product.checks.size > 0')
h2.stamp__content.is-title 確認済
Expand Down
26 changes: 13 additions & 13 deletions app/models/comment_callbacks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,54 +11,54 @@ def after_create(comment)

return unless comment.commentable.instance_of?(Product)

update_last_comment_at(comment)
update_last_commented_at(comment)
update_commented_at(comment)
delete_product_cache(comment.commentable.id)
end

def after_update(comment)
return unless comment.commentable.instance_of?(Product)

update_last_comment_at(comment)
update_last_commented_at(comment)
update_commented_at(comment)
end

def after_destroy(comment)
return unless comment.commentable.instance_of?(Product)

delete_last_comment_at(comment.commentable.id)
delete_last_commented_at(comment.commentable.id)
delete_commented_at(comment)
delete_product_cache(comment.commentable.id)
end

private

def reset_last_comment_at(product)
product.mentor_last_comment_at = nil
product.self_last_comment_at = nil
def reset_last_commented_at(product)
product.mentor_last_commented_at = nil
product.self_last_commented_at = nil
end

def delete_last_comment_at(product_id)
def delete_last_commented_at(product_id)
product = Product.find(product_id)

reset_last_comment_at(product)
reset_last_commented_at(product)

product.comments.each do |comment|
if comment.user.mentor
product.mentor_last_comment_at = comment.updated_at
product.mentor_last_commented_at = comment.updated_at
elsif comment.user == product.user
product.self_last_comment_at = comment.updated_at
product.self_last_commented_at = comment.updated_at
end
end
product.save!
end

def update_last_comment_at(comment)
def update_last_commented_at(comment)
product = Product.find(comment.commentable.id)
if comment.user.mentor
product.mentor_last_comment_at = comment.updated_at
product.mentor_last_commented_at = comment.updated_at
elsif comment.user == product.user
product.self_last_comment_at = comment.updated_at
product.self_last_commented_at = comment.updated_at
end
product.save!
end
Expand Down
12 changes: 6 additions & 6 deletions app/views/api/products/_product.json.jbuilder
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ if product.updated_at.present?
json.updated_at_date_time product.updated_at.to_datetime
end

if product.self_last_comment_at.present?
json.self_last_comment_at l(product.self_last_comment_at)
json.self_last_comment_at_date_time product.self_last_comment_at.to_datetime
if product.self_last_commented_at.present?
json.self_last_commented_at l(product.self_last_commented_at)
json.self_last_commented_at_date_time product.self_last_commented_at.to_datetime
end

if product.mentor_last_comment_at.present?
json.mentor_last_comment_at l(product.mentor_last_comment_at)
json.mentor_last_comment_at_date_time product.mentor_last_comment_at.to_datetime
if product.mentor_last_commented_at.present?
json.mentor_last_commented_at l(product.mentor_last_commented_at)
json.mentor_last_commented_at_date_time product.mentor_last_commented_at.to_datetime
end

json.user do
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class RenameSelfLastCommentAtToProducts < ActiveRecord::Migration[6.1]
def change
rename_column :products, :self_last_comment_at, :self_last_commented_at
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class RenameMentorLastCommentAtToProducts < ActiveRecord::Migration[6.1]
def change
rename_column :products, :mentor_last_comment_at, :mentor_last_commented_at
end
end
6 changes: 3 additions & 3 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: 2021_10_23_050713) do
ActiveRecord::Schema.define(version: 2021_11_10_063403) do

# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
Expand Down Expand Up @@ -315,8 +315,8 @@
t.boolean "wip", default: false, null: false
t.datetime "published_at"
t.bigint "checker_id"
t.datetime "self_last_comment_at"
t.datetime "mentor_last_comment_at"
t.datetime "self_last_commented_at"
t.datetime "mentor_last_commented_at"
t.datetime "commented_at"
t.index ["commented_at"], name: "index_products_on_commented_at"
t.index ["practice_id"], name: "index_products_on_practice_id"
Expand Down