Commit afef0409 authored by hh1966's avatar hh1966
Browse files

Add export api and a job to create export files

parent 4131ebcd
......@@ -65,6 +65,8 @@
/uploads/*
!/public/attachments/.keep
/public/json/*
!/public/json/.keep
/public/docx/*
!/public/docx/.keep
......
......@@ -123,4 +123,5 @@ class API < Grape::API
mount Chemotion::MessageAPI
mount Chemotion::AdminAPI
mount Chemotion::EditorAPI
mount Chemotion::ExportAPI
end
module Chemotion
class ExportAPI < Grape::API
resource :exports do
desc "Get export json for a collection"
params do
requires :collection_id, type: Integer, desc: 'collection id'
end
post do
ExportCollection.perform_later params
end
end
end
end
class ExportCollection < ActiveJob::Base
queue_as :export_collection
rescue_from(ActiveRecord::RecordNotFound) do; end
def perform(params)
require 'json'
collection = Collection.find(params[:collection_id])
export_file_name = "#{self.job_id}.json"
export_file_name = File.join('public', 'json', export_file_name)
export_file = File.new(export_file_name, 'w+')
export_file.write(collection.to_json)
export_file.close
end
end
Supports Markdown
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