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

123 lines
3.2 KiB
Ruby
Raw Normal View History

2016-07-25 15:20:01 +08:00
#coding=utf-8
module Mobile
module Apis
class Projects < Grape::API
resources :projects do
desc "获取项目列表"
params do
requires :token, type: String
end
get do
authenticate!
ps = ProjectsService.new
projects = ps.user_projects(current_user)
present :data, projects, with: Mobile::Entities::Project,user: current_user
present :status, 0
end
desc "返回单个项目"
params do
requires :id, type: Integer
requires :token,type:String
end
route_param :id do
get do
# course = Course.find(params[:id])
ps = ProjectsService.new
project = ps.show_project(params,current_user)
if project[:status] != 9
{status:-1, message: '该项目不存在或已被删除啦' }
else
present :data, project, with: Mobile::Entities::Project,user: current_user
present :status, 0
end
end
end
desc "获取项目动态"
params do
requires :token, type: String
end
post 'auth' do
authenticate!
auth = 0
if (current_user.user_extensions && current_user.user_extensions.identity == 0 && current_user.allowed_to?(:add_course, nil, :global => true))
auth = 1
end
present :auth, auth
end
desc "获取项目"
params do
requires :token, type: String
end
post 'auth' do
authenticate!
auth = 0
if (current_user.user_extensions && current_user.user_extensions.identity == 0 && current_user.allowed_to?(:add_course, nil, :global => true))
auth = 1
end
present :auth, auth
end
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,user: current_user
present :status, 0
end
end
desc '编辑大纲'
params do
requires :token, type: String
requires :title, type: String, desc: '大纲标题'
# requires :add_courses, type: Array[String], desc: '课程名'
# requires :modify_courses, type: Array[Integer,String], desc: '课程名'
end
post ':id/edit' do
authenticate!
ss = SyllabusesService.new
#修改课程大纲
status = ss.edit(current_user, params)
if status == -1
{status:status, message: '修改课程信息失败' }
else
present :status, status
end
end
end
end
end
end