diff --git a/app/api/mobile/apis/courses.rb b/app/api/mobile/apis/courses.rb index 08c7adf10..ce02f4249 100644 --- a/app/api/mobile/apis/courses.rb +++ b/app/api/mobile/apis/courses.rb @@ -228,6 +228,18 @@ module Mobile present :status, 0 end + desc '课程课件' + params do + requires :token, type: String + requires :course_id,type: Integer,desc: '课程id' + end + get ":course_id/attachments" do + cs = CoursesService.new + count = cs.course_attachments params + present :data, count, with: Mobile::Entities::Attachment + present :status, 0 + end + end end end diff --git a/app/api/mobile/entities/attachment.rb b/app/api/mobile/entities/attachment.rb index 510db89be..080b24558 100644 --- a/app/api/mobile/entities/attachment.rb +++ b/app/api/mobile/entities/attachment.rb @@ -16,8 +16,11 @@ module Mobile end end end + attachment_expose :id attachment_expose :filename attachment_expose :description + attachment_expose :downloads + attachment_expose :quotes end end end \ No newline at end of file diff --git a/app/services/courses_service.rb b/app/services/courses_service.rb index e91883bee..b992665d3 100644 --- a/app/services/courses_service.rb +++ b/app/services/courses_service.rb @@ -428,6 +428,17 @@ class CoursesService result end + # 课程课件 + def course_attachments params + result = [] + @course = Course.find(params[:course_id]) + @attachments = @course.attachments.order("created_on desc") + @attachments.each do |atta| + result << {:filename => atta.filename,:description => atta.description,:downloads => atta.downloads,:quotes => atta.quotes.nil? ? 0 :atta.quotes } + end + result + end + private def show_homework_info course,bid,current_user,is_course_teacher author_real_name = bid.author.lastname + bid.author.firstname