56 lines
1.5 KiB
Ruby
56 lines
1.5 KiB
Ruby
module Mobile
|
|
module Apis
|
|
class Users < Grape::API
|
|
resource :users do
|
|
desc "get all users"
|
|
get do
|
|
['hello']
|
|
end
|
|
|
|
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
|
|
end
|
|
|
|
|
|
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.merge(id: current_user.id)
|
|
{status: 0, data: ue}
|
|
rescue => e
|
|
{status: 1, message: e.message}
|
|
end
|
|
end
|
|
|
|
end
|
|
end
|
|
end
|
|
end
|
|
|
|
|