class Api::V1::Projects::Pulls::ReviewsController < Api::V1::Projects::Pulls::BaseController 

  def index 
    @reviews = @pull_request.reviews 
    @reviews = @reviews.where(status: params[:status]) if params[:status].present?
    # @reviews = kaminari_paginate(@reviews)
  end

  before_action :require_reviewer, only: [:create]

  def create 
    @review = Api::V1::Projects::Pulls::Reviews::CreateService.call(@project, @pull_request, review_params, current_user)
  end

  private 
  def require_reviewer
    return render_forbidden('您没有审查权限，请联系项目管理员') if !current_user.admin? && !@pull_request.reviewers.exists?(current_user.id) && !@project.manager?(current_user)
  end

  def review_params 
    params.require(:review).permit(:content, :commit_id, :status)
  end
end