diff --git a/app/api/mobile/apis/homeworks.rb b/app/api/mobile/apis/homeworks.rb index a7bb544af..abdf19390 100644 --- a/app/api/mobile/apis/homeworks.rb +++ b/app/api/mobile/apis/homeworks.rb @@ -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 diff --git a/app/api/mobile/entities/attachment.rb b/app/api/mobile/entities/attachment.rb new file mode 100644 index 000000000..510db89be --- /dev/null +++ b/app/api/mobile/entities/attachment.rb @@ -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 \ No newline at end of file diff --git a/app/api/mobile/entities/homework_attach.rb b/app/api/mobile/entities/homework_attach.rb index 8fa7a1dd1..256dcdf61 100644 --- a/app/api/mobile/entities/homework_attach.rb +++ b/app/api/mobile/entities/homework_attach.rb @@ -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) - f.send(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 diff --git a/app/services/homework_service.rb b/app/services/homework_service.rb index fe4b77404..33f74345f 100644 --- a/app/services/homework_service.rb +++ b/app/services/homework_service.rb @@ -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'} + end + @homework + #{:name => name, :description => desc, :datetime => format_time(datetime)} end #作品打分/留言