Class: PushType::Api::NodesController

Inherits:
PushType::ApiController show all
Defined in:
app/controllers/push_type/api/nodes_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



21
22
23
24
25
26
27
# File 'app/controllers/push_type/api/nodes_controller.rb', line 21

def create
  if @node.save
    render :show, status: :created
  else
    render json: { errors: @node.errors }, status: :unprocessable_entity
  end
end

#destroyObject



37
38
39
40
41
42
43
44
45
# File 'app/controllers/push_type/api/nodes_controller.rb', line 37

def destroy
  if @node.trashed?
    @node.destroy
    head :no_content
  else
    @node.trash!
    render :show
  end
end

#emptyObject



60
61
62
63
# File 'app/controllers/push_type/api/nodes_controller.rb', line 60

def empty
  PushType::Node.trashed.destroy_all
  head :no_content
end

#indexObject



9
10
11
# File 'app/controllers/push_type/api/nodes_controller.rb', line 9

def index
  @nodes = node_scope.not_trash.page(params[:page]).per(30)
end

#positionObject



47
48
49
50
51
52
53
# File 'app/controllers/push_type/api/nodes_controller.rb', line 47

def position
  if reorder_node
    head :no_content
  else
    render json: { errors: @node.errors }, status: :unprocessable_entity
  end
end

#restoreObject



55
56
57
58
# File 'app/controllers/push_type/api/nodes_controller.rb', line 55

def restore
  @node.restore!
  render :show
end

#showObject



18
19
# File 'app/controllers/push_type/api/nodes_controller.rb', line 18

def show
end

#trashObject



13
14
15
16
# File 'app/controllers/push_type/api/nodes_controller.rb', line 13

def trash
  @nodes = PushType::Node.all.trashed.page(params[:page]).per(30).reorder(deleted_at: :desc)
  render :index
end

#updateObject



29
30
31
32
33
34
35
# File 'app/controllers/push_type/api/nodes_controller.rb', line 29

def update
  if @node.update_attributes node_params_with_fields.merge(updater: push_type_user)
    render :show
  else
    render json: { errors: @node.errors }, status: :unprocessable_entity
  end
end