From b5dd2ade822d1fe5057f003adbac27444d48d17c Mon Sep 17 00:00:00 2001 From: chenjing Date: Tue, 12 Oct 2021 22:56:50 +0800 Subject: [PATCH] add Journals beihang --- app/controllers/journals_controller.rb | 33 ++++++++++++++++++++++---- config/routes.rb | 3 +++ 2 files changed, 32 insertions(+), 4 deletions(-) diff --git a/app/controllers/journals_controller.rb b/app/controllers/journals_controller.rb index ab00628d..5efd072f 100644 --- a/app/controllers/journals_controller.rb +++ b/app/controllers/journals_controller.rb @@ -1,5 +1,5 @@ class JournalsController < ApplicationController - before_action :require_login, except: [:index, :get_children_journals] + before_action :require_login, except: [:index, :get_children_journals,:beihang] before_action :require_profile_completed, only: [:create] before_action :set_issue before_action :check_issue_permission @@ -13,8 +13,8 @@ class JournalsController < ApplicationController parent_journals = total_journals.parent_journals.order("created_on desc") @journals = parent_journals.order("created_on desc").page(@page).per(@limit) @journals_size = parent_journals.size - - + + end def create @@ -52,6 +52,31 @@ class JournalsController < ApplicationController end end + def beihang + token = request.headers["HTTP_TOKEN"] + playod = JWT.decode(token,EducoderOauth.client_id)[0] + data = HashWithIndifferentAccess.new playod + + notes = params[:content] + return normal_status(-1, "评论内容不能为空") if notes.blank? + return normal_status(-1, "验证失败") if data["user_id"].blank? + journal_params = { + journalized_id: @issue.id , + journalized_type: "Issue", + user_id: data["user_id"] , + notes: notes.to_s.strip, + parent_id: params[:parent_id] + } + journal = Journal.new journal_params + if journal.save + # @issue.project_trends.create(user_id: current_user.id, project_id: @project.id, action_type: "journal") + render :json => { status: 0, message: "评论成功", id: journal.id} + # normal_status(0, "评论成功") + else + normal_status(-1, "评论失败") + end + end + def destroy if @journal.destroy #如果有子评论,子评论删除吗? Journal.children_journals(@journal.id).destroy_all @@ -110,4 +135,4 @@ class JournalsController < ApplicationController normal_status(-1, "评论不存在") end end -end \ No newline at end of file +end diff --git a/config/routes.rb b/config/routes.rb index 03b3ddbe..1369b457 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -138,6 +138,9 @@ Rails.application.routes.draw do resources :issues, except: [:index, :new,:create, :update, :edit, :destroy] do resources :journals, only: [:index, :create, :destroy, :edit, :update] do + collection do + post :beihang + end member do get :get_children_journals end