课程列表接口加入老师字段
This commit is contained in:
parent
3aea87b893
commit
ee3d998873
1
Gemfile
1
Gemfile
|
@ -9,6 +9,7 @@ unless RUBY_PLATFORM =~ /w32/
|
||||||
end
|
end
|
||||||
|
|
||||||
gem 'grape', '~> 0.9.0'
|
gem 'grape', '~> 0.9.0'
|
||||||
|
gem 'grape-entity'
|
||||||
gem 'seems_rateable', path: 'lib/seems_rateable'
|
gem 'seems_rateable', path: 'lib/seems_rateable'
|
||||||
gem "rails", "3.2.13"
|
gem "rails", "3.2.13"
|
||||||
gem "jquery-rails", "~> 2.0.2"
|
gem "jquery-rails", "~> 2.0.2"
|
||||||
|
|
|
@ -107,6 +107,9 @@ GEM
|
||||||
rack-accept
|
rack-accept
|
||||||
rack-mount
|
rack-mount
|
||||||
virtus (>= 1.0.0)
|
virtus (>= 1.0.0)
|
||||||
|
grape-entity (0.4.4)
|
||||||
|
activesupport
|
||||||
|
multi_json (>= 1.3.2)
|
||||||
guard (2.6.1)
|
guard (2.6.1)
|
||||||
formatador (>= 0.2.4)
|
formatador (>= 0.2.4)
|
||||||
listen (~> 2.7)
|
listen (~> 2.7)
|
||||||
|
@ -303,6 +306,7 @@ DEPENDENCIES
|
||||||
factory_girl (~> 4.4.0)
|
factory_girl (~> 4.4.0)
|
||||||
fastercsv (~> 1.5.0)
|
fastercsv (~> 1.5.0)
|
||||||
grape (~> 0.9.0)
|
grape (~> 0.9.0)
|
||||||
|
grape-entity
|
||||||
guard-rails (~> 0.5.3)
|
guard-rails (~> 0.5.3)
|
||||||
guard-spork (~> 1.5.1)
|
guard-spork (~> 1.5.1)
|
||||||
guard-test (~> 1.0.0)
|
guard-test (~> 1.0.0)
|
||||||
|
|
|
@ -1,27 +1,57 @@
|
||||||
module Mobile
|
module Mobile
|
||||||
|
|
||||||
|
module Entities
|
||||||
|
|
||||||
|
class Course < Grape::Entity
|
||||||
|
def self.course_expose(field)
|
||||||
|
expose field do |f,opt|
|
||||||
|
f[:course][field] || f[:course].__send__(field)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
expose :img_url
|
||||||
|
course_expose :attachmenttype
|
||||||
|
course_expose :class_period
|
||||||
|
course_expose :code
|
||||||
|
course_expose :created_at
|
||||||
|
course_expose :description
|
||||||
|
course_expose :endup_time
|
||||||
|
course_expose :extra
|
||||||
|
course_expose :id
|
||||||
|
course_expose :inherit_members
|
||||||
|
course_expose :is_public
|
||||||
|
course_expose :lft
|
||||||
|
course_expose :location
|
||||||
|
course_expose :name
|
||||||
|
course_expose :open_student
|
||||||
|
# course_expose :password
|
||||||
|
course_expose :rgt
|
||||||
|
course_expose :school_id
|
||||||
|
course_expose :setup_time
|
||||||
|
course_expose :state
|
||||||
|
course_expose :status
|
||||||
|
course_expose :string
|
||||||
|
course_expose :tea_id
|
||||||
|
course_expose :term
|
||||||
|
course_expose :time
|
||||||
|
course_expose :updated_at
|
||||||
|
course_expose :teacher
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
class Courses < Grape::API
|
class Courses < Grape::API
|
||||||
resource :courses do
|
resource :courses do
|
||||||
desc "get all courses"
|
desc "get all courses"
|
||||||
params do
|
params do
|
||||||
|
optional :school_id, type: Integer, desc: 'school number'
|
||||||
requires :per_page_count, type: Integer
|
requires :per_page_count, type: Integer
|
||||||
requires :page, type: Integer, desc: 'current page no'
|
requires :page, type: Integer, desc: 'current page no'
|
||||||
end
|
end
|
||||||
get do
|
get do
|
||||||
per_page_option = params[:per_page_count] || 10
|
cs = CoursesService.new
|
||||||
page_no = params[:page] || 1
|
courses = cs.course_list(params)
|
||||||
@courses_all = Course.active.visible.
|
present :data, courses, with: Entities::Course
|
||||||
joins("LEFT JOIN #{CourseStatus.table_name} ON #{Course.table_name}.id = #{CourseStatus.table_name}.course_id")
|
present :status, 0
|
||||||
@course_count = @courses_all.count
|
|
||||||
@course_pages = Redmine::Pagination::Paginator.new @course_count, per_page_option,page_no
|
|
||||||
@course_activity_count=Hash.new
|
|
||||||
@courses_all.each do |course|
|
|
||||||
@course_activity_count[course.id]=0
|
|
||||||
end
|
|
||||||
@courses = @courses_all.order("created_at desc")
|
|
||||||
@s_type = 0
|
|
||||||
@courses = @courses.offset(@course_pages.offset).limit(@course_pages.per_page)
|
|
||||||
{status: 0, data: @courses}
|
|
||||||
# @course_activity_count=get_course_activity @courses, @course_activity_count
|
|
||||||
end
|
end
|
||||||
|
|
||||||
desc "Return a course"
|
desc "Return a course"
|
||||||
|
|
Loading…
Reference in New Issue