gitlink-forgeplus/app/controllers/api/v1/issues/journals_controller.rb

39 lines
1.0 KiB
Ruby

class Api::V1::Issues::JournalsController < Api::V1::IssuesController
before_action :require_public_and_member_above, only: [:index, :create, :destroy]
before_action :load_issue, only: [:index, :create, :destroy]
before_action :load_journal, only: [:destroy]
def index
@object_results = Api::V1::Issues::Journals::ListService.call(@issue, query_params, current_user)
@journals = kaminari_paginate(@object_results)
end
def create
@object_result = Api::V1::Issues::Journals::CreateService.call(@issue, journal_params, current_user)
end
def destroy
if @journal.destroy!
render_ok
else
render_error("删除评论失败!")
end
end
private
def query_params
params.permit(:category, :keyword, :sort_by, :sort_direction)
end
def journal_params
params.permit(:notes, :parent_id, :attachment_ids => [])
end
def load_journal
@journal = @issue.journals.find_by_id(params[:id])
return render_not_found("评论不存在!") unless @journal.present?
end
end