Merge remote-tracking branch 'origin/dev_aliyun' into dev_aliyun

dev_admin
杨树明 6 years ago
commit 0c6b2c198a

@ -22,7 +22,7 @@ class LibrariesController < ApplicationController
end
@count = libraries.count
@libraries = paginate libraries.includes(:library_tags, :praise_tread_cache, user: :user_extension)
@libraries = paginate libraries.includes(:library_tags, user: :user_extension)
ids = @libraries.map(&:id)
@download_count_map = Attachment.where(container_type: 'Library', container_id: ids)

@ -85,7 +85,7 @@ class MemosController < ApplicationController
params[:tags].each do |tag|
MemoTagRepertoire.create!(memo_id: @memo.id, tag_repertoire_id: tag)
end
normal_status("帖子创建成功")
render :json => {memo_id: @memo.id, status: 0, message: "帖子创建成功"}
rescue Exception => e
tip_exception("帖子创建失败,原因:#{e}")
raise ActiveRecord::Rollback

@ -10,6 +10,8 @@ class Library < ApplicationRecord
has_many :attachments, as: :container
has_one :praise_tread_cache, foreign_key: :object_id
has_many :praise_treads, as: :praise_tread_object, dependent: :destroy
validates :uuid, presence: true, uniqueness: true

@ -26,13 +26,13 @@ elsif @type =="qrcode"
json.qrcode_str @qrcode_str
elsif @type == "mp3" || @type == "mp4"
if @type == "mp4"
json.orignal_file [{"file_url": "http://120.27.231.56:48080/attachments/download/378171"}]
json.user_file [{"file_url": "http://120.27.231.56:48080/attachments/download/378172"}]
json.answer_file [{"file_url": "http://120.27.231.56:48080/attachments/download/378173"}]
json.orignal_file [{"file_url": "http://120.27.231.56:48080/attachments/download/378171/123.mp4"}]
json.user_file [{"file_url": "http://120.27.231.56:48080/attachments/download/378172/456.mp4"}]
json.answer_file [{"file_url": "http://120.27.231.56:48080/attachments/download/378173/789.mp4"}]
else
json.orignal_file [{"file_url": "http://120.27.231.56:48080/attachments/download/378174"}]
json.user_file [{"file_url": "http://120.27.231.56:48080/attachments/download/378175"}]
json.answer_file [{"file_url": "http://120.27.231.56:48080/attachments/download/378175"}]
json.orignal_file [{"file_url": "http://120.27.231.56:48080/attachments/download/378174/58099.mp3"}]
json.user_file [{"file_url": "http://120.27.231.56:48080/attachments/download/378175/654058514.mp3"}]
json.answer_file [{"file_url": "http://120.27.231.56:48080/attachments/download/378175/654058514.mp3"}]
end
# json.orignal_file do
# json.array! @orignal_picture do |file|

@ -5,7 +5,7 @@ json.libraries do
json.cover_url library.cover_id.present? ? download_url(library.cover) : nil
json.praise_count library.praise_tread_cache&.praise_num || 0
json.praise_count library.praises_count
json.download_count @download_count_map.fetch(library.id, 0)
json.published_at library.display_published_at

@ -2,7 +2,7 @@ library = current_library
json.extract! library, :id, :uuid, :title, :content, :author_name, :author_school_name, :status, :visited_count
json.praise_count library.praise_tread_cache&.praise_num || 0
json.praise_count library.praises_count
json.published_at library.display_published_at
json.created_at library.display_created_at

@ -9,6 +9,6 @@ json.memo do
json.tag memo.tag_repertoires.map(&:name)
json.time memo.created_at
json.replies_count memo.all_replies_count
json.user_praise memo.praise_treads.user_liker(@user.try(:id)) ? true : false
json.user_praise memo.praise_treads.user_liker(@user.try(:id)).count > 1 ? true : false
json.memo_praise_count memo.praise_treads.liker.count
end

@ -5,6 +5,7 @@ Rails.application.routes.draw do
mount Sidekiq::Web => '/sidekiq', :constraints => AdminConstraint.new
get 'attachments/download/:id', to: 'attachments#show'
get 'attachments/download/:id/:filename', to: 'attachments#show'
resources :edu_settings
scope '/api' do

@ -0,0 +1,12 @@
class AddPraisesCountToMemos < ActiveRecord::Migration[5.2]
def change
add_column :memos, :praises_count, :integer, :default => 0
memos = Memo.includes(:praise_treads).all
memos.find_each do |m|
puts("####{m.id}")
praises_count = m.praise_treads.select{|pt| pt.praise_or_tread == 1}.count
m.update_column(:praises_count, praises_count)
end
end
end

@ -0,0 +1,10 @@
class AddPraisesCountToLibraries < ActiveRecord::Migration[5.2]
def change
add_column :libraries, :praises_count, :integer, :default => 0
Library.find_each do |library|
praises_count = library.praise_treads.count
library.update_column(:praises_count, praises_count)
end
end
end
Loading…
Cancel
Save