Fix RFC lists for RFCs without comments

This commit is contained in:
Maximilian Grundke
2017-08-13 16:09:44 +02:00
parent ba8511fe40
commit 06f11ae6f5

View File

@ -11,28 +11,44 @@ class RequestForCommentsController < ApplicationController
# GET /request_for_comments # GET /request_for_comments
# GET /request_for_comments.json # GET /request_for_comments.json
def index def index
@search = RequestForComment.last_per_user(2).search(params[:q]) @search = RequestForComment
.last_per_user(2)
.joins('join "submissions" s on s.id = request_for_comments.submission_id
left outer join "files" f on f.context_id = s.id
left outer join "comments" on comments.file_id = f.id')
.group('request_for_comments.id, request_for_comments.user_id, request_for_comments.exercise_id,
request_for_comments.file_id, request_for_comments.question, request_for_comments.created_at,
request_for_comments.updated_at, request_for_comments.user_type, request_for_comments.solved,
request_for_comments.submission_id, request_for_comments.row_number') # ugly, but rails wants it this way
.select('request_for_comments.*, max(comments.updated_at) as last_comment')
.search(params[:q])
@request_for_comments = @search.result.order('created_at DESC').paginate(page: params[:page]) @request_for_comments = @search.result.order('created_at DESC').paginate(page: params[:page])
authorize! authorize!
end end
def get_my_comment_requests def get_my_comment_requests
@search = RequestForComment.where(user_id: current_user.id).order('created_at DESC').search(params[:q]) @search = RequestForComment
@request_for_comments = @search.result.paginate(page: params[:page]) .where(user_id: current_user.id)
.joins('join "submissions" s on s.id = request_for_comments.submission_id
left outer join "files" f on f.context_id = s.id
left outer join "comments" on comments.file_id = f.id')
.group('request_for_comments.id')
.select('request_for_comments.*, max(comments.updated_at) as last_comment')
.search(params[:q])
@request_for_comments = @search.result.order('created_at DESC').paginate(page: params[:page])
render 'index' render 'index'
end end
def get_rfcs_with_my_comments def get_rfcs_with_my_comments
@search = RequestForComment @search = RequestForComment
.joins(:comments) .joins(:comments) # we don't need to outer join here, because we know the user has commented on these
.where(comments: {user_id: current_user.id}) .where(comments: {user_id: current_user.id})
.group('request_for_comments.id') .group('request_for_comments.id')
.joins(:comments) .joins(:comments)
.group('request_for_comments.id') .group('request_for_comments.id')
.select('request_for_comments.*, max(comments.updated_at) as last_comment') .select('request_for_comments.*, max(comments.updated_at) as last_comment')
.order('last_comment DESC')
.search(params[:q]) .search(params[:q])
@request_for_comments = @search.result.paginate(page: params[:page]) @request_for_comments = @search.result.order('last_comment DESC').paginate(page: params[:page])
render 'index' render 'index'
end end