Commit 631722ab by liyijie

Add import & export API

parent ed132273
...@@ -28,6 +28,17 @@ class SimpleController::BaseController < ::InheritedResources::Base ...@@ -28,6 +28,17 @@ class SimpleController::BaseController < ::InheritedResources::Base
super(options, &block) super(options, &block)
end end
def import
xlsx_file = params[:file]
response = import_class.import_xlsx xlsx_file, collection, params.to_unsafe_h
render json: response, status: 201
end
def export
url = export_class.export_xlsx collection, params.to_unsafe_h
render json: { url: url }, status: 201
end
protected protected
class << self class << self
...@@ -42,6 +53,11 @@ class SimpleController::BaseController < ::InheritedResources::Base ...@@ -42,6 +53,11 @@ class SimpleController::BaseController < ::InheritedResources::Base
set_view_path view_path if view_path.present? set_view_path view_path if view_path.present?
super(options) super(options)
self.class_attribute :import_class, instance_writer: false unless self.respond_to? :import_class
self.class_attribute :export_class, instance_writer: false unless self.respond_to? :export_class
self.import_class = options.delete(:import_class) || self.resource_class
self.export_class = options.delete(:export_class) || self.resource_class
end end
def set_view_path path def set_view_path path
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment