2014-11-27 19:43:04 +08:00
|
|
|
module Mobile
|
2014-12-08 16:51:21 +08:00
|
|
|
|
|
|
|
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
|
|
|
|
|
2014-11-27 19:43:04 +08:00
|
|
|
class Courses < Grape::API
|
|
|
|
resource :courses do
|
|
|
|
desc "get all courses"
|
|
|
|
params do
|
2014-12-08 16:51:21 +08:00
|
|
|
optional :school_id, type: Integer, desc: 'school number'
|
2014-11-27 19:43:04 +08:00
|
|
|
requires :per_page_count, type: Integer
|
|
|
|
requires :page, type: Integer, desc: 'current page no'
|
|
|
|
end
|
|
|
|
get do
|
2014-12-08 16:51:21 +08:00
|
|
|
cs = CoursesService.new
|
|
|
|
courses = cs.course_list(params)
|
|
|
|
present :data, courses, with: Entities::Course
|
|
|
|
present :status, 0
|
2014-11-27 19:43:04 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
desc "Return a course"
|
|
|
|
params do
|
|
|
|
requires :id, type: Integer
|
|
|
|
end
|
|
|
|
route_param :id do
|
|
|
|
get do
|
2014-12-03 17:28:19 +08:00
|
|
|
course = Course.find(params[:id])
|
|
|
|
{status: 0, data: course}
|
2014-11-27 19:43:04 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|