Class: Api::NetworksController

Inherits:
ApplicationController show all
Defined in:
app/controllers/api/networks_controller.rb

Instance Method Summary collapse

Methods included from Response

#json_response

Instance Method Details

#createObject



28
29
30
31
# File 'app/controllers/api/networks_controller.rb', line 28

def create
  NetworkCsvMakerWorker.perform_async
  render json: { data: 'The network is being created... please check back on the API' }, status: :ok
end

#destroyObject



33
34
35
36
37
38
39
# File 'app/controllers/api/networks_controller.rb', line 33

def destroy
  if @network.destroy
    render json: { data: 'The network has been deleted' }, status: :ok
  else
    render json: { data: 'Something went wrong' }, status: :unprocessable_entity
  end
end

#indexObject

before_action :sanitize, only: [:create, :update]



13
14
15
16
17
18
19
20
21
22
# File 'app/controllers/api/networks_controller.rb', line 13

def index
  networks = Network.all.map do |network|
    {
      id: network.id,
      created_at: network.created_at,
      updated_at: network.updated_at
    }
  end
  json_response(networks)
end

#showObject



24
25
26
# File 'app/controllers/api/networks_controller.rb', line 24

def show
  render json: @network, serializer: Api::NetworkSerializer
end