mirror of
https://gitlink.org.cn/Gitlink/forgeplus.git
synced 2026-05-02 19:30:48 +08:00
init project
This commit is contained in:
21
app/views/libraries/index.json.jbuilder
Normal file
21
app/views/libraries/index.json.jbuilder
Normal file
@@ -0,0 +1,21 @@
|
||||
json.count @count
|
||||
json.libraries do
|
||||
json.array! @libraries.each do |library|
|
||||
json.extract! library, :id, :title, :content, :author_name, :author_school_name, :status, :visited_count
|
||||
|
||||
json.cover_url library.cover_id.present? ? download_url(library.cover) : nil
|
||||
|
||||
json.praise_count library.praises_count
|
||||
json.download_count @download_count_map.fetch(library.id, 0)
|
||||
|
||||
json.published_at library.display_published_at
|
||||
json.created_at library.display_created_at
|
||||
|
||||
# 标签
|
||||
json.tags do
|
||||
json.array! library.library_tags.each do |tag|
|
||||
json.extract! tag, :id, :name
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
47
app/views/libraries/show.json.jbuilder
Normal file
47
app/views/libraries/show.json.jbuilder
Normal file
@@ -0,0 +1,47 @@
|
||||
library = current_library
|
||||
|
||||
json.extract! library, :id, :uuid, :title, :content, :author_name, :author_school_name, :status, :visited_count
|
||||
|
||||
json.praise_count library.praises_count
|
||||
|
||||
json.published_at library.display_published_at
|
||||
json.created_at library.display_created_at
|
||||
|
||||
# 创建者
|
||||
json.creator do
|
||||
json.partial! 'users/user_simple', user: library.user
|
||||
json.school_name library.user.school_name
|
||||
end
|
||||
|
||||
# 封面
|
||||
if library.cover_id.present?
|
||||
json.cover do
|
||||
json.partial! 'attachments/attachment_simple', attachment: library.cover
|
||||
end
|
||||
else
|
||||
json.cover nil
|
||||
end
|
||||
|
||||
json.attachments library.attachments, partial: 'attachments/attachment_small', as: :attachment
|
||||
|
||||
# 标签
|
||||
json.tags do
|
||||
json.array! library.library_tags.each do |tag|
|
||||
json.extract! tag, :id, :name
|
||||
end
|
||||
end
|
||||
|
||||
# 操作权限
|
||||
json.operation do
|
||||
if current_user&.logged?
|
||||
manageable = library_manageable?(library)
|
||||
|
||||
json.can_deletable manageable
|
||||
json.can_editable manageable
|
||||
json.user_praised library.praise_treads.exists?(user_id: current_user&.id)
|
||||
else
|
||||
json.can_deletable false
|
||||
json.can_editable false
|
||||
json.user_praised false
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user