class ReviewsController < ApplicationController
  before_action :require_login
  before_action :load_project 
  before_action :load_pull_request

  def create 
    return render_forbidden('您不是审查人员，无法进行审查！') if current_user&.id != @pull_request.issue.assigned_to_id
    @review = Api::V1::Projects::Pulls::Reviews::CreateService.call(@project, @pull_request, review_params, current_user)
  end

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

  def load_pull_request
    @pull_request = @project.pull_requests.where(gitea_number: params[:id]).where.not(id: params[:id]).take || @project.pull_requests.find_by_id(params[:id])
  end

end