Code Cleanup: Usage of Polymorphic User instead of ExternalUser and InternalUser

Renamed requestor_user_id -> user_id
Index of request_for_comments now returns the n (5?) newest requests per user. Solved via sliding windows in postgres, code added to model.
Added route to /my_request_for_comments/ that shows all requests for the current user.
Changed view from ERB to slim
This commit is contained in:
Ralf Teusner
2015-09-03 19:04:38 +02:00
parent 8e9f19f41d
commit d292fec47c
15 changed files with 78 additions and 47 deletions

View File

@ -1,7 +1,20 @@
class RequestForComment < ActiveRecord::Base
before_create :set_requested_timestamp
belongs_to :exercise
belongs_to :file, class: CodeOcean::File
belongs_to :user, polymorphic: true
before_create :set_requested_timestamp
def self.last_per_user(n = 5)
from("(#{row_number_user_sql}) as request_for_comments").where("row_number <= ?", n)
end
def set_requested_timestamp
self.requested_at = Time.now
end
private
def self.row_number_user_sql
select("id, user_id, exercise_id, file_id, requested_at, created_at, updated_at, user_type, row_number() OVER (PARTITION BY user_id ORDER BY created_at DESC) as row_number").to_sql
end
end