generated from espoo-dev/rails_boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathusers_controller.rb
More file actions
39 lines (30 loc) · 840 Bytes
/
users_controller.rb
File metadata and controls
39 lines (30 loc) · 840 Bytes
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
# frozen_string_literal: true
module Api
module V1
class UsersController < ApiController
def index
users = User.page(page).per(per_page)
authorize(users)
render json: users, status: :ok
end
def destroy_self
authorize current_user, :destroy_self?
unless current_user.valid_password?(params[:password])
return render json: { error: "Wrong password" }, status: :unauthorized
end
if current_user.destroy
render json: { message: "Account deleted successfully" }, status: :ok
else
render json: { error: "Unable to delete account" }, status: :unprocessable_entity
end
end
private
def page
params[:page]
end
def per_page
params[:per_page]
end
end
end
end