mirror of
https://github.com/we-promise/sure.git
synced 2026-05-07 12:54:04 +00:00
feat(api): expose import row diagnostics (#1644)
* feat(api): expose import row diagnostics * fix(api): stabilize import row diagnostics * fix(api): harden import row diagnostics * fix(api): number Mint import diagnostics rows * fix(api): enforce unique import row diagnostics * fix(api): address import row diagnostics review
This commit is contained in:
@@ -4,9 +4,10 @@ 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, :rows ]
|
||||
before_action :ensure_write_scope, only: [ :create ]
|
||||
before_action :set_import, only: [ :show ]
|
||||
before_action :set_import_with_rows, only: [ :show ]
|
||||
before_action :set_import, only: [ :rows ]
|
||||
|
||||
def index
|
||||
family = current_resource_owner.family
|
||||
@@ -44,6 +45,22 @@ class Api::V1::ImportsController < Api::V1::BaseController
|
||||
render json: { error: "internal_server_error", message: e.message }, status: :internal_server_error
|
||||
end
|
||||
|
||||
def rows
|
||||
@per_page = safe_per_page_param
|
||||
@pagy, @rows = pagy(
|
||||
@import.rows_ordered,
|
||||
page: safe_page_param,
|
||||
limit: @per_page
|
||||
)
|
||||
@rows.each(&:valid?)
|
||||
@row_mapping_lookup = @import.mappings.includes(:mappable).index_by { |mapping| [ mapping.type, mapping.key.to_s ] }
|
||||
|
||||
render :rows
|
||||
rescue StandardError => e
|
||||
Rails.logger.error "ImportsController#rows error: #{e.message}"
|
||||
render json: { error: "internal_server_error", message: e.message }, status: :internal_server_error
|
||||
end
|
||||
|
||||
def create
|
||||
family = current_resource_owner.family
|
||||
|
||||
@@ -122,8 +139,22 @@ class Api::V1::ImportsController < Api::V1::BaseController
|
||||
private
|
||||
|
||||
def set_import
|
||||
@import = current_resource_owner.family.imports.includes(:rows).find(params[:id])
|
||||
@import = import_scope.find(params[:id])
|
||||
rescue ActiveRecord::RecordNotFound
|
||||
render_import_not_found
|
||||
end
|
||||
|
||||
def set_import_with_rows
|
||||
@import = import_scope.includes(:rows).find(params[:id])
|
||||
rescue ActiveRecord::RecordNotFound
|
||||
render_import_not_found
|
||||
end
|
||||
|
||||
def import_scope
|
||||
current_resource_owner.family.imports
|
||||
end
|
||||
|
||||
def render_import_not_found
|
||||
render json: { error: "not_found", message: "Import not found" }, status: :not_found
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user