initial commit
This commit is contained in:
@@ -0,0 +1,15 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module Api
|
||||
class ApiBaseController < ActionController::API
|
||||
include ActiveStorage::SetCurrent
|
||||
|
||||
before_action :authenticate_user!
|
||||
|
||||
private
|
||||
|
||||
def current_account
|
||||
current_user&.account
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,20 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module Api
|
||||
class AttachmentsController < ApiBaseController
|
||||
skip_before_action :authenticate_user!
|
||||
|
||||
def create
|
||||
submission = Submission.find_by!(slug: params[:submission_slug])
|
||||
blob = ActiveStorage::Blob.find_signed(params[:blob_signed_id])
|
||||
|
||||
attachment = ActiveStorage::Attachment.create!(
|
||||
blob:,
|
||||
name: params[:name],
|
||||
record: submission
|
||||
)
|
||||
|
||||
render json: attachment.as_json(only: %i[uuid], methods: %i[url filename content_type])
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,22 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module Api
|
||||
class FlowsController < ApiBaseController
|
||||
def update
|
||||
@flow = current_account.flows.find(params[:id])
|
||||
|
||||
@flow.update!(flow_params)
|
||||
|
||||
render :ok
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def flow_params
|
||||
params.require(:flow).permit(:name,
|
||||
schema: [%i[attachment_uuid name]],
|
||||
fields: [[:uuid, :name, :type, :required,
|
||||
{ options: [], areas: [%i[x y w h attachment_uuid page]] }]])
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,31 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module Api
|
||||
class FlowsDocumentsController < ApiBaseController
|
||||
def create
|
||||
@flow = current_account.flows.find(params[:flow_id])
|
||||
|
||||
documents =
|
||||
params[:blobs].map do |blob|
|
||||
blob = ActiveStorage::Blob.find_signed(blob[:signed_id])
|
||||
|
||||
document = @flow.documents.create!(blob:)
|
||||
|
||||
Flows::ProcessDocument.call(document)
|
||||
end
|
||||
|
||||
schema = documents.map do |doc|
|
||||
{ attachment_uuid: doc.uuid, name: doc.filename.base }
|
||||
end
|
||||
|
||||
render json: {
|
||||
schema:,
|
||||
documents: documents.as_json(
|
||||
include: {
|
||||
preview_images: { methods: %i[url metadata filename] }
|
||||
}
|
||||
)
|
||||
}
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user