|
- class Api::V1::Issues::JournalsController < Api::V1::IssuesController
-
- before_action :require_public_and_member_above, only: [:index, :create, :children_journals, :update, :destroy]
- before_action :load_issue, only: [:index, :create, :children_journals, :update, :destroy]
- before_action :load_journal, only: [:children_journals, :update, :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 children_journals
- @object_results = Api::V1::Issues::Journals::ChildrenListService.call(@issue, @journal, query_params, current_user)
- @journals = kaminari_paginate(@object_results)
- end
-
- def update
- @object_result = Api::V1::Issues::Journals::UpdateService.call(@issue, @journal, 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, :reply_id, :attachment_ids => [])
- end
-
- def load_journal
- @journal = Journal.find_by_id(params[:id])
- return render_not_found("评论不存在!") unless @journal.present?
- end
-
- end
|