Skip to content
Closed
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 31 additions & 2 deletions app/controllers/api/v1/imports_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ class Api::V1::ImportsController < Api::V1::BaseController
include Pagy::Backend

# Ensure proper scope authorization
before_action :ensure_read_scope, only: [ :index, :show ]
before_action :ensure_read_scope, only: [ :index, :show, :preflight ]
before_action :ensure_write_scope, only: [ :create ]
before_action :set_import, only: [ :show ]

Expand Down Expand Up @@ -119,6 +119,30 @@ def create
render json: { error: "internal_server_error", message: e.message }, status: :internal_server_error
end

def preflight
response = Import::Preflight.new(family: current_resource_owner.family, params: preflight_params).call
render json: response.payload, status: response.status
rescue ActiveRecord::RecordNotFound
render json: {
error: "record_not_found",
message: "The requested resource was not found"
}, status: :not_found
rescue CSV::MalformedCSVError => e
render json: {
error: "invalid_csv",
message: "CSV content could not be parsed",
errors: [ e.message ]
}, status: :unprocessable_entity
rescue StandardError => e
Rails.logger.error "ImportsController#preflight error: #{e.message}"
e.backtrace&.each { |line| Rails.logger.error line }

render json: {
error: "internal_server_error",
message: "An unexpected error occurred"
}, status: :internal_server_error
Comment thread
coderabbitai[bot] marked this conversation as resolved.
end
Comment thread
coderabbitai[bot] marked this conversation as resolved.

private

def set_import
Expand Down Expand Up @@ -155,10 +179,15 @@ def import_config_params
:signage_convention,
:col_sep,
:amount_type_strategy,
:amount_type_inflow_value
:amount_type_inflow_value,
:rows_to_skip
)
end

def preflight_params
params.permit(*Import::Preflight::PARAM_KEYS)
end

def create_sure_import(family)
content, filename, content_type = sure_import_upload_attributes
return unless content
Expand Down
Loading
Loading