Class: SupplejackApi::UserSetsController
Instance Method Summary
collapse
#authenticate_admin!, #authenticate_user!, #current_user, #find_user_set
Instance Method Details
#admin_index ⇒ Object
Endpoint for the administrator to get a list of sets for any user.
25
26
27
28
29
30
31
32
33
34
|
# File 'app/controllers/supplejack_api/user_sets_controller.rb', line 25
def admin_index
@user = User.find_by_api_key(params[:user_id])
if @user
@user_sets = @user.user_sets
render json: serializable_array(@user_sets).to_json
else
render json: { errors: "The user with api key: '#{params[:user_id]}' was not found" }, status: :not_found
end
end
|
#create ⇒ Object
57
58
59
60
61
62
63
64
|
# File 'app/controllers/supplejack_api/user_sets_controller.rb', line 57
def create
@user_set = current_user.user_sets.build
if @user_set.update_attributes_and_embedded(params[:set])
render json: UserSetSerializer.new(@user_set, user: true)
else
render json: { errors: @user_set.errors.to_hash }, status: :unprocessable_entity
end
end
|
#destroy ⇒ Object
74
75
76
77
|
# File 'app/controllers/supplejack_api/user_sets_controller.rb', line 74
def destroy
@user_set.destroy
respond_with(@user_set)
end
|
#featured_sets_index ⇒ Object
43
44
45
46
|
# File 'app/controllers/supplejack_api/user_sets_controller.rb', line 43
def featured_sets_index
@user_sets = UserSet.featured_sets(4)
render json: serializable_array(@user_sets, user: true, featured: true).to_json
end
|
#index ⇒ Object
18
19
20
21
|
# File 'app/controllers/supplejack_api/user_sets_controller.rb', line 18
def index
@user_sets = current_user.user_sets
render json: serializable_array(@user_sets).to_json
end
|
#public_index ⇒ Object
Enpoint for the administrator to fetch a list of all public sets
38
39
40
41
|
# File 'app/controllers/supplejack_api/user_sets_controller.rb', line 38
def public_index
@user_sets = UserSet.public_sets(page: params[:page])
render json: serializable_array(@user_sets, user: true, total: true).to_json
end
|
#show ⇒ Object
48
49
50
51
52
53
54
55
|
# File 'app/controllers/supplejack_api/user_sets_controller.rb', line 48
def show
@user_set = UserSet.custom_find(params[:id])
if @user_set
render json: UserSetSerializer.new(@user_set, user: current_user)
else
render json: { errors: "Set with id: #{params[:id]} was not found." }, status: :not_found
end
end
|
#update ⇒ Object
66
67
68
69
70
71
72
|
# File 'app/controllers/supplejack_api/user_sets_controller.rb', line 66
def update
if @user_set.update_attributes_and_embedded(params[:set], current_user)
render json: UserSetSerializer.new(@user_set, user: true)
else
render json: { errors: @user_set.errors.to_hash }, status: :unprocessable_entity
end
end
|