Class: V1::PackagesController

Inherits:
ApplicationController show all
Defined in:
app/controllers/v1/packages_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


28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'app/controllers/v1/packages_controller.rb', line 28

def create
  PackagesPolicy.new(current_user).authorize! :create?
  status, @request_record = RequestBuilder.new
    .create(create_params.merge(user: current_user))
  case status
  when :duplicate
    head 303, location: v1_request_path(@request_record)
  when :created
    head 201, location: v1_request_path(@request_record)
  when :invalid
    render json: @request_record.errors, status: :unprocessable_entity
  end
end

#indexObject

GET /packages


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

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

  @packages = policy.resolve
end

#sendfileObject


22
23
24
25
# File 'app/controllers/v1/packages_controller.rb', line 22

def sendfile
  PackagePolicy.new(current_user, package).authorize! :show?
  send_file(*PackageFileGetter.new(package).sendfile(params[:file]))
end

#showObject

GET /packages/1 GET /packages/39015012345678


18
19
20
# File 'app/controllers/v1/packages_controller.rb', line 18

def show
  PackagePolicy.new(current_user, package).authorize! :show?
end