profiles.rb
1.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
module Api
module V1
class Profiles < Grape::API
resource :profiles do
get do
profiles = select_filtered_collection_of(environment, 'profiles', params)
profiles = profiles.visible
profiles = profiles.by_location(params) # Must be the last. May return Exception obj.
present profiles, :with => Entities::Profile, :current_person => current_person
end
get ':id' do
profiles = environment.profiles
profiles = profiles.visible
profile = profiles.find_by id: params[:id]
if profile
present profile, :with => Entities::Profile, :current_person => current_person
else
not_found!
end
end
desc "Update profile information"
post ':id' do
authenticate!
profile = environment.profiles.find_by(id: params[:id])
return forbidden! unless profile.allow_edit?(current_person)
profile.update_attributes!(asset_with_image(params[:profile]))
present profile, :with => Entities::Profile, :current_person => current_person
end
delete ':id' do
authenticate!
profiles = environment.profiles
profile = profiles.find_by id: params[:id]
not_found! if profile.blank?
if profile.allow_destroy?(current_person)
profile.destroy
else
forbidden!
end
end
end
end
end
end