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

56 lines
1.5 KiB
Ruby
Raw Normal View History

2014-11-27 19:43:04 +08:00
module Mobile
module Apis
2014-12-09 16:36:43 +08:00
class Users < Grape::API
resource :users do
desc "get all users"
get do
['hello']
end
2014-12-04 10:11:55 +08:00
2014-12-09 16:36:43 +08:00
desc "add a user"
params do
requires :login, type: String, desc: 'username'
requires :mail, type: String, desc: 'mail'
requires :password, type: String, desc: 'password'
end
post do
us = UsersService.new
begin
user = us.register params.merge(:password_confirmation => params[:password],
:should_confirmation_password => true)
raise "register failed #{user.errors.full_messages}" if user.new_record?
present :data, user, with: Mobile::Entities::User
present :status, 0
rescue => e
{status: 1, message: e.message}
end
2014-11-27 19:43:04 +08:00
end
2014-12-10 11:56:33 +08:00
desc "modify user"
params do
#optional :file, type: File, desc: 'avatar'
optional :occupation, type: String
optional :brief_introduction, type: String
optional :province, type: String
optional :city, type: String
optional :gender, type: Integer
end
put ':id' do
authenticate!
us = UsersService.new
begin
ue = us.edit_user params
{status: 0, data: ue}
rescue => e
{status: 1, message: e.message}
end
end
end
2014-11-27 19:43:04 +08:00
end
end
end