socialforge/app/api/mobile/apis/syllabuses.rb

64 lines
1.4 KiB
Ruby
Raw Normal View History

2016-07-04 16:19:05 +08:00
#coding=utf-8
module Mobile
module Apis
class Syllabuses < Grape::API
resources :syllabuses do
desc "获取大纲列表"
params do
requires :token, type: String
end
get do
authenticate!
cs = SyllabusesService.new
courses = cs.user_syllabus(current_user)
present :data, courses, with: Mobile::Entities::Syllabus
present :status, 0
end
2016-07-04 17:04:06 +08:00
desc "获取某个大纲"
params do
requires :token, type: String
end
get ':id' do
authenticate!
sy = ::Syllabus.find(params[:id])
present :data, sy, with: Mobile::Entities::Syllabus
present :status, 0
end
2016-07-04 16:19:05 +08:00
desc "新建大纲"
params do
requires :token, type: String
requires :title, type: String, desc: '大纲标题'
requires :courses, type: Array[String], desc: '课程名'
end
post do
authenticate!
ss = SyllabusesService.new
sy = ss.create(current_user, params[:title],
params[:courses].map{|c| {name: c} })
if sy.new_record?
{status:-1, message: '创建大纲失败' }
else
present :data, sy, with: Mobile::Entities::Syllabus
present :status, 0
end
end
2016-07-04 17:04:06 +08:00
2016-07-04 16:19:05 +08:00
end
end
end
end