Class: V1::QueueItemsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/v1/queue_items_controller.rb

Instance Attribute Summary

Attributes inherited from ApplicationController

#current_user

Instance Method Summary collapse

Methods inherited from ApplicationController

#fake_user

Instance Method Details

#createObject

POST /v1/requests/:bag_id/complete


23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'app/controllers/v1/queue_items_controller.rb', line 23

def create
  request = Package.find_by_bag_id!(params[:bag_id])
  authorize_create!(request)
  status, @queue_item = QueueItemBuilder.new.create(request)
  case status
  when :duplicate
    head 303, location: v1_queue_item_path(@queue_item)
  when :created
    head 201, location: v1_queue_item_path(@queue_item)
  when :invalid
    render json: @queue_item.errors, status: :unprocessable_entity
  else
    raise [status, @queue_item]
  end
end

#indexObject

GET /v1/queue


8
9
10
11
12
13
# File 'app/controllers/v1/queue_items_controller.rb', line 8

def index
  policy = QueueItemsPolicy.new(current_user)
  policy.authorize! :index?

  @queue_items = policy.resolve
end

#showObject

GET /v1/queue/:id


16
17
18
19
20
# File 'app/controllers/v1/queue_items_controller.rb', line 16

def show
  @queue_item = QueueItem.find(params[:id])
  QueueItemPolicy.new(current_user, @queue_item).authorize! :show?
  render template: "v1/queue_items/show", status: 200
end