匿评作品详情显示接口
This commit is contained in:
parent
b6207c0a47
commit
a4d7e5f932
|
@ -59,6 +59,17 @@ module Mobile
|
|||
present :status, 0
|
||||
end
|
||||
|
||||
desc "匿评作品详情"
|
||||
params do
|
||||
requires :token, type: String
|
||||
end
|
||||
get ':homework_id/anonymous_works_show' do
|
||||
works = Homeworks.get_service.anonymous_works_show params
|
||||
present :data, works ,with: Mobile::Entities::HomeworkAttach
|
||||
present :status, 0
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -0,0 +1,23 @@
|
|||
module Mobile
|
||||
module Entities
|
||||
class Attachment < Grape::Entity
|
||||
def self.attachment_expose(field)
|
||||
expose field do |f,opt|
|
||||
if f.is_a?(Hash) && f.key?(field)
|
||||
f[field]
|
||||
elsif f.is_a?(::Attachment)
|
||||
if f.respond_to?(field)
|
||||
f.send(field)
|
||||
else
|
||||
#case field
|
||||
# when ""
|
||||
#end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
attachment_expose :filename
|
||||
attachment_expose :description
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,18 +1,22 @@
|
|||
module Mobile
|
||||
module Entities
|
||||
class HomeworkAttach < Grape::Entity
|
||||
include Redmine::I18n
|
||||
def self.homework_attach_expose(field)
|
||||
expose field do |f,opt|
|
||||
if f.is_a?(Hash) && f.key?(field)
|
||||
f[field]
|
||||
elsif f.is_a?(::HomeworkAttach)
|
||||
if f.respond_to?(field)
|
||||
if field == :created_at
|
||||
format_time(f.send(:created_at))
|
||||
else
|
||||
f.send(field)
|
||||
end
|
||||
else
|
||||
case field
|
||||
when :homework_times
|
||||
f.bid.courses.first.homeworks.index(f.bid) + 1 unless (f.bid.nil? || f.bid.courses.nil? || f.bid.courses.first.nil?)
|
||||
#course.homeworks.index(@bid) + 1
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -22,6 +26,13 @@ module Mobile
|
|||
homework_attach_expose :id
|
||||
homework_attach_expose :name
|
||||
homework_attach_expose :homework_times
|
||||
homework_attach_expose :description
|
||||
homework_attach_expose :created_at
|
||||
expose :attachments,using: Mobile::Entities::Attachment do |f, opt|
|
||||
if f.respond_to?(:attachments)
|
||||
f.send(:attachments)
|
||||
end
|
||||
end
|
||||
#homework_attach_expose :user
|
||||
end
|
||||
end
|
||||
|
|
|
@ -105,15 +105,16 @@ class HomeworkService
|
|||
name = @homework.name
|
||||
desc = @homework.description
|
||||
datetime = @homework.created_at
|
||||
files = []
|
||||
unless @homework.attachments.empty?
|
||||
attachs = @homework.attachments
|
||||
attachs.each do |attach|
|
||||
filename = attach.name
|
||||
filedesc = attach.description unless attachment.description.blank?
|
||||
filename = attach.filename
|
||||
filedesc = attach.description unless attach.description.blank?
|
||||
end
|
||||
end
|
||||
{:name => 'name', :description => 'desc', :datetime => 'datetime',
|
||||
:attchs => 'attachs', :filename => 'filename', :filedesc => 'filedesc'}
|
||||
@homework
|
||||
#{:name => name, :description => desc, :datetime => format_time(datetime)}
|
||||
end
|
||||
|
||||
#作品打分/留言
|
||||
|
|
Loading…
Reference in New Issue