1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2024-12-01 12:24:28 +01:00
fab-manager/app/controllers/api/supporting_document_files_controller.rb

54 lines
1.9 KiB
Ruby
Raw Normal View History

# frozen_string_literal: true
# API Controller for resources of type SupportingDocumentFile
# SupportingDocumentFiles are used in settings
2023-02-24 17:26:55 +01:00
class API::SupportingDocumentFilesController < API::APIController
before_action :authenticate_user!
before_action :set_supporting_document_file, only: %i[show update download]
def index
@supporting_document_files = SupportingDocumentFileService.list(current_user, params)
end
# PUT /api/supporting_document_files/1/
def update
authorize @supporting_document_file
if SupportingDocumentFileService.update(@supporting_document_file, supporting_document_file_params)
render :show, status: :ok, location: @supporting_document_file
else
render json: @supporting_document_file.errors, status: :unprocessable_entity
end
end
# POST /api/supporting_document_files/
def create
@supporting_document_file = SupportingDocumentFile.new(supporting_document_file_params)
authorize @supporting_document_file
if SupportingDocumentFileService.create(@supporting_document_file)
render :show, status: :created, location: @supporting_document_file
else
render json: @supporting_document_file.errors, status: :unprocessable_entity
end
end
# GET /api/supporting_document_files/1/download
def download
authorize @supporting_document_file
send_file @supporting_document_file.attachment.url, type: @supporting_document_file.attachment.content_type, disposition: 'attachment'
end
# GET /api/supporting_document_files/1/
def show; end
private
def set_supporting_document_file
@supporting_document_file = SupportingDocumentFile.find(params[:id])
end
# Never trust parameters from the scary internet, only allow the white list through.
def supporting_document_file_params
params.required(:supporting_document_file).permit(:supporting_document_type_id, :attachment, :supportable_id, :supportable_type)
end
end